Sometimes you come to a moment when you need to convert xml to php array. It may have different reasons. So here i am going to show how it works.
To do it, simply read a xml file. Encode all the content with json_encode which returns a JSON Object. Decode the JSON object as array by giving as the second parameter a 1. And viola, you have converted XML to PHP Array
1 2 3 4 5 6 |
/ load xml file $xmlStr = simplexml_load_string( $filename ); $jsonObj = json_encode($xmlStr); $xmlArray= json_decode($jsonObj, 1); // see result var_dump($xmlArray); |
Have fun, folks.