Search code examples
phpcastingsimplexml

Recursive cast from SimpleXMLObject to Array


I need to recursively cast a PHP SimpleXMLObject to an array. The problem is that each sub element is also a PHP SimpleXMLElement.

Is this possible?


Solution

  • json_decode(json_encode((array) simplexml_load_string($obj)), 1);