$data = [ 'a' => [ 'b' => [ 'c' => 'leaf value', 'd' => 'another leaf value' ] ] ]; $iterator = new RecursiveArrayIterator($data); $riIterator = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::LEAVES_ONLY); foreach ($riIterator as $key => $value) { echo $key . ' => ' . $value . '
'; }
$dirIterator = new RecursiveDirectoryIterator('/path/to/directory'); $riIterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::SELF_FIRST); foreach ($riIterator as $file) { echo $file->getPathname() . 'Package library: The RecursiveIteratorIterator class is a part of the core PHP language and is included in the standard PHP library.
'; }