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!


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


Posted in php

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.