I am creating an array, named $subArray. This array has to be filled with $child->getName() => $child, gotten from a XML document.
$subArray = array(
foreach($person->children() as $child){
$child->getName() => $child;
}
);
But this doesn't seem to work, as I cannot use the => when using array_push, and I cannot use a foreach loop inside an array. How do I solve this?
This is my whole function:
function get_xml_arr($xmlURL){
$xml=simplexml_load_file($xmlURL) or die ("XML not found");
$array = array();
foreach($xml->person as $person){
$subArray = array(
foreach($person->children() as $child){
$child->getName() => $child;
}
);
array_push($array, $subArray);
}
return $array;
}