3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function Recurse1($xml) { foreach ($xml->children() as $child) { if (is_iterable($child)) { if (!isset($array)) { $array = Recurse1($child); } else { $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 tIIND
Output for 7.1.0 - 7.3.0rc3
Notice: Undefined variable: array in /in/Q1n9j on line 16 Notice: Undefined variable: array in /in/Q1n9j on line 16 NULL
Output for 7.0.28
Fatal error: Uncaught Error: Call to undefined function is_iterable() in /in/Q1n9j:6 Stack trace: #0 /in/Q1n9j(30): Recurse1(Object(SimpleXMLElement)) #1 {main} thrown in /in/Q1n9j on line 6
Process exited with code 255.
Output for 5.6.38
Fatal error: Call to undefined function is_iterable() in /in/Q1n9j on line 6
Process exited with code 255.