SimpleXMLElement to PHP Array [duplicate] SimpleXMLElement to PHP Array [duplicate] arrays arrays

SimpleXMLElement to PHP Array [duplicate]


In this simple case type casting will also work:

$my_array = (array)$answer


This should work:

$xml = simplexml_load_string($xmlstring);$json = json_encode($xml);$array = json_decode($json,TRUE);


The $answer can already work as an array. You can do this if you want put it in a real array,

$array = array();foreach($answer as $k => $v) {  $array[$k] = $v;}