PHP : Converting attributes of an XML object to an Array
Input
Published in
1 min readFeb 5, 2018
$xmlString = "
<sequencer name=\"AXX\" slug=\"axx\">
<sequencer name=\"BER\" slug=\"ber\"></sequencer>
</sequencer>
";
Code
$xmlObject = new SimpleXMLElement($xmlString);
$xmlAttributes = $xmlObject->attributes();// current() method takes care of the conversion
$xmlAttributesArray = current($xmlAttributes);
Output
[
"name" => "AXX"
"slug" => "axx"
]