Quickly convert simpleXMLObject to STDClass?

Pekka picture Pekka · Oct 18, 2009 · Viewed 14.7k times · Source

Does anybody know a quick way to convert a SimpleXMLElement to a normal STDClass object, without iterating through each branch manually? I would feel better working with a normal object after fetching the data.

Answer

Skyler Johnson picture Skyler Johnson · Mar 19, 2011
$my_std_class = json_decode(json_encode($my_simplexmlelement));
$my_assoc_array = json_decode(json_encode($my_simplexmlelement), true);