<?php
$myArray = array(
0,
array(
0,
1,
array(
0,
1,
2,
array(
0,
1,
2,
3,
array("the end")
)
)
)
);
$recursive_array_iterator = new RecursiveArrayIterator($myArray);
iterator_apply($recursive_array_iterator, 'traverseRecursiveArray', array($recursive_array_iterator));
$i = 0;
function traverseRecursiveArray($iterator)
{
while ($iterator->valid()) {
if ($iterator->hasChildren()) {
traverseRecursiveArray($iterator->getChildren());
} else {
echo $iterator->key() . ' => ' . $iterator->current() . PHP_EOL;
}
$iterator->current .= $i++;
$iterator->next();
}
}
preferences:
44.83 ms | 402 KiB | 5 Q