Batches item.
array $items An array of items:
integer $size The size of the batch:
string $fill A string to fill missing items:
array
function twig_array_batch($items, $size, $fill = null) {
if ($items instanceof Traversable) {
$items = iterator_to_array($items, false);
}
$size = ceil($size);
$result = array_chunk($items, $size, true);
if (null !== $fill) {
$last = count($result) - 1;
$result[$last] = array_merge($result[$last], array_fill(0, $size - count($result[$last]), $fill));
}
return $result;
}