的SimpleXMLElement到PHP数组 [英] SimpleXMLElement to PHP Array
本文介绍了的SimpleXMLElement到PHP数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
变量$ D受到的file_get_contents功能的URL。
Variable $d comes from file_get_contents function to a url.
$answer = @new SimpleXMLElement($d);
下面是的print_r($回答)的输出:
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? can't figure it out.
推荐答案
该$答案已经可以工作,作为一个数组。你可以做到这一点,如果你希望把它放在一个真实的阵列,
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;
}
这篇关于的SimpleXMLElement到PHP数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文