SimpleXMLElement to PHP Array [duplicate]
问题 This question already has answers here : Recursive cast from SimpleXMLObject to Array (5 answers) Closed 4 years ago . 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. 回答1: The $answer can already work as an array. You can do this