3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array( array( 'category_id' => 1, 'children' => array( 'category_id' => 2, 'children' => array( 'category_id' => 3, ) ) ), array( 'category_id' => 4, 'children' => array( 'category_id' => 5, 'children' => array( 'category_id' => 6, ) ) ) ); $iterator = new RecursiveIteratorIterator( new RecursiveArrayIterator($array) ); for($iterator; $iterator->valid(); $iterator->next()) { printf( "Key: %s Value: %s Depth: %s\n", $iterator->key(), $iterator->current(), $iterator->getDepth() ); }

preferences:
33.58 ms | 402 KiB | 5 Q