3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function Recurse1($xml, $array = []) { foreach ($xml->children() as $child) { if (is_iterable($child)) { $array = array_merge($array, Recurse1($child)); } else { $array[] = (string)$xml['role']; } } return $array; } $xml = new SimpleXMLElement( '<person> <child role="son1"> <child role="daughter1"/> </child> <child role="daughter2"> <child role="son2"> <child role="son3"/> </child> </child> </person>'); var_dump(Recurse1($xml));
based on Q1n9j
Output for 7.1.0 - 7.3.0rc3
array(0) { }
Output for 7.0.28
Fatal error: Uncaught Error: Call to undefined function is_iterable() in /in/X4bNv:6 Stack trace: #0 /in/X4bNv(26): Recurse1(Object(SimpleXMLElement)) #1 {main} thrown in /in/X4bNv on line 6
Process exited with code 255.
Output for 5.6.38
Fatal error: Call to undefined function is_iterable() in /in/X4bNv on line 6
Process exited with code 255.