- var_dump: documentation ( source)
- array_merge: documentation ( source)
<?php
function Recurse1($xml)
{
$array = [(string)$xml['role']];
foreach ($xml->children() as $child)
{
$array = array_merge($array, Recurse1($child));
}
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));