3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array = array( array("title" => 1, "children" => array( array( "selected" => true, "key" => 12345, "children" => array() ) ) ) ); $selectedValues = array(); $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($array)); foreach ($iterator as $key => $value) { if ($key == "selected" && $value) { $selectedValues[] = $iterator["key"]; } } var_dump($selectedValues);
based on bQ5sK
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Cannot use object of type RecursiveIteratorIterator as array in /in/arGlO:16 Stack trace: #0 {main} thrown in /in/arGlO on line 16
Process exited with code 255.
Output for 5.3.17 - 5.6.28
Fatal error: Cannot use object of type RecursiveIteratorIterator as array in /in/arGlO on line 16
Process exited with code 255.