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($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.
推荐答案
$answer
已经可以用作数组.如果你想把它放在一个真正的数组中,你可以这样做,
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屋!
查看全文