I need to parse XML string into an array.
I have XML
<group xmlns="123" id="personal">
<field id="last_name">last</field>
<field id="first_name">first</field>
<field id="birth_day">10/10/1990</field>
<field id="gender"/>
</group>
I’m using SimpleXML in php
$obj = simplexml_load_string($xml_string);
var_dump($obj);
SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => personal
)
[field] => Array
(
[0] => first
[1] => last
[2] => 10/10/1990
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => gender
)
)
)
)
how to get such array? is it possible?
[field] => Array(
[last_name] => last,
[first_name] => first,
[birth_day] => 10/10/1990,
[gender] => NULL,
....
)
I do not know how else to explain this situation.
I want to index the id attribute value were.
please help.
Simple as that (Note it uses PHP 5.3 features):
Output (null value is not shown by
print_r):