Turn a SimpleXML object into a PHP array

Nice simple quick trick but makes dealing with SimpleXML so much easier!

Basically grab your XML into a variable. JSON Encode it then JSON decode it and Ta da!

Example:

bc. $array = json_decode(json_encode((array)simplexml_load_string($xml)),1);

Enjoy!

Posted in php

Leave a Reply

Your email address will not be published. Required fields are marked *