SimpleXMLElement to PHP Array
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;
}
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);