- array_reverse: documentation ( source)
- var_export: documentation ( source)
- range: documentation ( source)
- is_callable: documentation ( source)
<?php
// Everything you enter here will be executed by our servers. Try it!
function iterator_compose()
{
foreach (array_reverse(func_get_args()) as $it) {
if (is_callable($it)) {
$prev = $it;
}
}
}
function iterator_chunk(\Traversable $it, $chunkSize)
{
$it = new \IteratorIterator($it);
$chunk = [];
$steps = range(0, $chunkSize);
while (true) {
foreach ($steps as $_) {
$chunk[] = $it->current();
$it->next();
if (!$it->valid()) {
break 1;
}
}
yield $chunk;
$chunk = [];
}
if ($chunk) {
yield $chunk;
}
}
$it = new ArrayIterator(range(0, 125));
foreach (iterator_chunk($it, 32) as $i => $c) {
echo "====== Chunk $i ======\n";
var_export($c);
echo "\n";
}