SimpleXMLElement to PHP Array

arrays, php, simplexml, xml

Solution

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;
}

Problem

Variable `$d` comes from `file_get_contents` function to a URL. ``` $answer = @new SimpleXMLElement($d); ``` Below is output of the `print_r($answer)`: ``` SimpleXMLElement Object ( [Amount] => 2698 [Status] => OK [State] => FL [Country] => USA ) ``` How can I retrieve value of each element and add to an array? I can't figure it out.

Original source

Related problems