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($tree)); foreach ($iterator as $key => $value) { if ($key == "selected" && $value) { $selectedValues[] = $iterator["key"]; } } var_dump($selectedValues);
based on f19a2
Output for 7.0.20, 7.1.5 - 7.2.0
Notice: Undefined variable: tree in /in/bQ5sK on line 13 Fatal error: Uncaught InvalidArgumentException: Passed variable is not an array or object in /in/bQ5sK:13 Stack trace: #0 /in/bQ5sK(13): ArrayIterator->__construct(NULL) #1 {main} thrown in /in/bQ5sK on line 13
Process exited with code 255.
Output for 7.0.0 - 7.0.6, 7.1.0
Notice: Undefined variable: tree in /in/bQ5sK on line 13 Fatal error: Uncaught InvalidArgumentException: Passed variable is not an array or object, using empty array instead in /in/bQ5sK:13 Stack trace: #0 /in/bQ5sK(13): ArrayIterator->__construct(NULL) #1 {main} thrown in /in/bQ5sK on line 13
Process exited with code 255.
Output for 5.3.17 - 5.6.28
Notice: Undefined variable: tree in /in/bQ5sK on line 13 Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Passed variable is not an array or object, using empty array instead' in /in/bQ5sK:13 Stack trace: #0 /in/bQ5sK(13): ArrayIterator->__construct(NULL) #1 {main} thrown in /in/bQ5sK on line 13
Process exited with code 255.