3v4l.org

run code in 300+ PHP versions simultaneously
<?php // extend the RecursiveIteratorIterator class ULRows extends RecursiveIteratorIterator { function __construct($it) { // here we use the parent class and use LEAVES_ONLY to parent::__construct($it, self::LEAVES_ONLY); } function beginChildren() { echo '<ul>'; } function endChildren() { echo '</ul>' . "\n"; } } /** * * an array of animal ** */ $animals = array( array('type' => 'dog','name' => 'butch','sex' => 'm','breed' => 'boxer'), array('type' => 'dog','name' => 'fido','sex' => 'm','breed' => 'doberman'), array('type' => 'dog','name' => 'girly','sex' => 'f','breed' => 'poodle'), array('type' => 'cat','name' => 'tiddles','sex' => 'm','breed' => 'ragdoll'), array('type' => 'cat','name' => 'tiddles','sex' => 'f','breed' => 'manx'), array('type' => 'cat','name' => 'tiddles','sex' => 'm','breed' => 'maine coon'), array('type' => 'horse','name' => 'ed','sex' => 'm','breed' => 'clydesdale'), array('type' => 'perl_coder','name' => 'shadda','sex' => 'none','breed' => 'mongrel'), array('type' => 'duck','name' => 'galapogus','sex' => 'm','breed' => 'pekin')); /** * * create a new recursive array iterator ** */ $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator(new ArrayIterator($animals))); /** * * traverse the $iterator object ** */ while ( $iterator->valid() ) { var_dump($iterator->current()); echo "<li>" . $iterator->current() . '</li>'; $iterator->next(); } ?>

preferences:
35.87 ms | 402 KiB | 5 Q