在调用prestashop webservice之后,我收到了响应,如下所示:
SimpleXMLElement Object
(
[order] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 1
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 2
)
)
)
)
我尝试通过循环来检索内容,如下所示:
foreach($resources as $resource){
echo '<pre>';
print_r($resource['id']);
echo '</pre>';
}
这给了我:
SimpleXMLElement Object
(
[0] => 1
)
SimpleXMLElement Object
(
[0] => 2
)
如何检索1和2这些对象的值?感谢
答案 0 :(得分:1)
我讨厌simplexml ......
<?php
$xml = file_get_contents('xml.xml');
$xml = new SimpleXMLElement($xml);
foreach($xml as $key => $value)
{
$attrs = $value->attributes();
foreach($attrs as $attr_k => $attr_v)
echo $attr_k.": ".$attr_v."\n";
}