Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

RecursiveArrayIterator

RecursiveArrayIterator extends ArrayIterator to allow recursive iteration over nested arrays and objects. It implements RecursiveIterator, so it works with RecursiveIteratorIterator to traverse multidimensional arrays depth-first.

<?php

    $array = ['a', ['b', 'c'], ['d', ['e', 'f']]];
    $iterator = new RecursiveIteratorIterator(
        new RecursiveArrayIterator($array)
    );
    
    foreach ($iterator as $value) {
        echo $value . PHP_EOL;
    }
    // a b c d e f

?>

Documentation

See Also