hi there,

am new to this forum, so thanks for listening.

i'm working with third party provided web service which i can't expose publicly unfortunately. however, i've set up the soap client etc and upon calling a particular method and getting the following back in response to doing a print_r on the result:

stdClass Object
(
[GetUserPersDetailsResult] => stdClass Object
(
[IDNo] => 350773
[Title] => Lord
[GivenName] => Andrew
[Surname] => Gunter
[CompanyName] =>
[Addr1] => Some Road
[Addr2] =>
[Addr3] =>
[Suburb] => Some Suburb
[State] => QLD
[PostCode] => 4213
[Country] => au
[Phone1] =>
[Phone2] =>
[Phone3] =>
[Fax] =>
[EmailAddr] => andrewg@xxx.com.au
[SuppressMail] => 1
)

)

i know this is dumb stuff and i know it's not an array but an object but i'm struggling (all night) to try to particular elements (?) from the object. i've tried all manner of things including:

echo $result[3]->Surname; // to get surname

for($i = 0; $i<count($result); $i++) { // trying another way
echo $result[$i]->Surname . "<br>\n";
}

this just gives me a "cannot use object of type stdClass as array" error which i know but didn't think i was trying to do....

i figure i'm being dumb here cos when i do a count($result) i get an answer of "1" when there should be a bunch of elements. can anyone point in me the right direction re iterating through the results and also plucking out one element?

many many thanks,
andrewg.

    This should give you the Surname:

    echo $result->GetUserPersDetailsResult->Surname;

    A better solution might be to use, e.g., SimpleXML.

      thanks installer!

      got that to work and got some iteration happening as well. it sure is a shocker though to try to extract data. the next case i've been looking at is even more complex with an array of stdClass objects that i have to navigate.

      thanks for the advice. one question though about simplexml. i've been doing some reading on it but i'm not sure how architecturally that would work? i was using soap client in order to interact with the wiz-del file and thereby get to and from the dbase that it front ends. so i can't see how i can get away from that? and using soap client as i see it converts everything so that i'm not dealing with xml anyway??

      sorry for being obtuse,
      andrewg.

        Write a Reply...