3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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(); } ?>
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(4) { ["type"]=> string(3) "dog" ["name"]=> string(5) "butch" ["sex"]=> string(1) "m" ["breed"]=> string(5) "boxer" } Notice: Array to string conversion in /in/jj1Rh on line 44 <li>Array</li>string(3) "dog" <li>dog</li>string(5) "butch" <li>butch</li>string(1) "m" <li>m</li>string(5) "boxer" <li>boxer</li>string(3) "dog" <li>dog</li>string(4) "fido" <li>fido</li>string(1) "m" <li>m</li>string(8) "doberman" <li>doberman</li>string(3) "dog" <li>dog</li>string(5) "girly" <li>girly</li>string(1) "f" <li>f</li>string(6) "poodle" <li>poodle</li>string(3) "cat" <li>cat</li>string(7) "tiddles" <li>tiddles</li>string(1) "m" <li>m</li>string(7) "ragdoll" <li>ragdoll</li>string(3) "cat" <li>cat</li>string(7) "tiddles" <li>tiddles</li>string(1) "f" <li>f</li>string(4) "manx" <li>manx</li>string(3) "cat" <li>cat</li>string(7) "tiddles" <li>tiddles</li>string(1) "m" <li>m</li>string(10) "maine coon" <li>maine coon</li>string(5) "horse" <li>horse</li>string(2) "ed" <li>ed</li>string(1) "m" <li>m</li>string(10) "clydesdale" <li>clydesdale</li>string(10) "perl_coder" <li>perl_coder</li>string(6) "shadda" <li>shadda</li>string(4) "none" <li>none</li>string(7) "mongrel" <li>mongrel</li>string(4) "duck" <li>duck</li>string(9) "galapogus" <li>galapogus</li>string(1) "m" <li>m</li>string(5) "pekin" <li>pekin</li>
Output for 5.1.0 - 5.3.29
array(4) { ["type"]=> string(3) "dog" ["name"]=> string(5) "butch" ["sex"]=> string(1) "m" ["breed"]=> string(5) "boxer" } <li>Array</li>string(3) "dog" <li>dog</li>string(5) "butch" <li>butch</li>string(1) "m" <li>m</li>string(5) "boxer" <li>boxer</li>string(3) "dog" <li>dog</li>string(4) "fido" <li>fido</li>string(1) "m" <li>m</li>string(8) "doberman" <li>doberman</li>string(3) "dog" <li>dog</li>string(5) "girly" <li>girly</li>string(1) "f" <li>f</li>string(6) "poodle" <li>poodle</li>string(3) "cat" <li>cat</li>string(7) "tiddles" <li>tiddles</li>string(1) "m" <li>m</li>string(7) "ragdoll" <li>ragdoll</li>string(3) "cat" <li>cat</li>string(7) "tiddles" <li>tiddles</li>string(1) "f" <li>f</li>string(4) "manx" <li>manx</li>string(3) "cat" <li>cat</li>string(7) "tiddles" <li>tiddles</li>string(1) "m" <li>m</li>string(10) "maine coon" <li>maine coon</li>string(5) "horse" <li>horse</li>string(2) "ed" <li>ed</li>string(1) "m" <li>m</li>string(10) "clydesdale" <li>clydesdale</li>string(10) "perl_coder" <li>perl_coder</li>string(6) "shadda" <li>shadda</li>string(4) "none" <li>none</li>string(7) "mongrel" <li>mongrel</li>string(4) "duck" <li>duck</li>string(9) "galapogus" <li>galapogus</li>string(1) "m" <li>m</li>string(5) "pekin" <li>pekin</li>
Output for 5.0.0 - 5.0.5
Fatal error: Class 'RecursiveArrayIterator' not found in /in/jj1Rh on line 37
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected ')', expecting '(' in /in/jj1Rh on line 8
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected ')', expecting '(' in /in/jj1Rh on line 8
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'('' in /in/jj1Rh on line 8
Process exited with code 255.