1

I have a SOAP request that is returning an array of IDs. For some reason, I am having trouble accessing the array within the SimpleXML element.

I did a vardump of the simplexml object:

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" } } 

And then a var dump of what I though would be the array:

die(var_dump($POList->int));
object(SimpleXMLElement)#8 (1) { [0]=> string(5) "20622" }

How do I access this array?

2
  • If you're making Soap requests why wouldn't you use the built-in SOAP Client? There's even scripts out there that will generate the classes for you Commented Jul 2, 2012 at 16:17
  • @Cfreak Because SOAP Client doesnt seem to like this .net webservice. I've managed to get the request in soapclient, but the only way ive been able to parse the response is to grab the XML and put it through SimpleXML Commented Jul 2, 2012 at 16:21

1 Answer 1

2

SimpleXMLElement implements Traversable, so you should be able to do:

foreach( $POList->int as $el)
    echo $el;

Or possibly query the array from xpath:

$array = $POList->xpath( '/int')[0];
foreach( $array as $el)
    echo $el;
Sign up to request clarification or add additional context in comments.

2 Comments

The second example did not work, but the first did allow me to iterate over the items and rebuild an array.
The syntax in that second example will only work in PHP 5.4 onwards, as previous versions will reject the combination of function and array syntax of the form foo()[0].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.