我有一个返回ID数组的SOAP请求。出于某种原因,我在SimpleXML元素中访问数组时遇到问题。
我做了一个simplexml对象的vardump:
die(var_dump($POList));
object(SimpleXMLElement)#7 (1) { ["int"]=> array(10) { [0]=> string(5) "20622" [1]=> string(5) "20868" [2]=> string(5) "20880" [3]=> string(5) "20883" [4]=> string(5) "21034" [5]=> string(5) "21065" [6]=> string(5) "21136" [7]=> string(5) "21160" [8]=> string(5) "21202" [9]=> string(5) "21247" } }
然后是我将成为数组的var转储:
die(var_dump($POList->int));
object(SimpleXMLElement)#8 (1) { [0]=> string(5) "20622" }
如何访问此阵列?
答案 0 :(得分:2)
SimpleXMLElement
实现Traversable
,因此您应该能够:
foreach( $POList->int as $el)
echo $el;
或者可能从xpath查询数组:
$array = $POList->xpath( '/int')[0];
foreach( $array as $el)
echo $el;