I am using following code to parse the following xml and add the id of each person as key of the array and their names as the values of the array.
The code properly works but the array is not.
$array = array();
$category = $xml->xpath('descendant::person');
foreach ($person as $p) {
$array[$p['id']] = $p['name'];
}
<?xml version="1.0" encoding="utf-8"?>
<people>
<person name="Joe" id="134">
<person name="Jack" id="267">
</person>
</person>
<person name="Ray" id="388">
<person name="John" id="485">
<person name="Rayan" id="900">
</person>
</person>
<person name="Alex" id="590">
</person>
</people>
The XML is not valid but I ca not make it valid. However the code is working and I just need to assign the ids and values to the array.