You are here

function twig_array_batch in Translation template extractor 6.3

Same name and namespace in other branches
  1. 7.3 vendor/Twig/Extension/Core.php \twig_array_batch()

Batches item.

Parameters

array $items An array of items:

int $size The size of the batch:

mixed $fill A value used to fill missing items:

Return value

array

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

File

vendor/Twig/Extension/Core.php, line 1478

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;
    if ($fillCount = $size - count($result[$last])) {
      $result[$last] = array_merge($result[$last], array_fill(0, $fillCount, $fill));
    }
  }
  return $result;
}