function twig_array_batch

Batches item.

Parameters

array $items An array of items:

integer $size The size of the batch:

string $fill A string to fill missing items:

Return value

array

1 string reference to 'twig_array_batch'
Twig_Extension_Core::getFilters in drupal/core/vendor/twig/twig/lib/Twig/Extension/Core.php
Returns a list of filters to add to the existing list.

File

drupal/core/vendor/twig/twig/lib/Twig/Extension/Core.php, line 1325

Code

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;
}