Page 1 of 1

Displaying SOAP requesxt output

Posted: Mon Oct 21, 2013 12:11 pm
by scary
Hi

I'm trying to process the output from a SOAP request. So far I've only managed to work out how to display the parent part of the output using the following code:

How do I display the children in this array?

$oResponse receives the output from a soap request.

Code: Select all

foreach($oResponse->oCategoryTree->oCategory as $details)
{
  echo $details->sName . "<br />";
}
The example SOAP output is:
[text]
stdClass Object
(
[oCategoryTree] => stdClass Object
(
[oCategory] => Array
(
[0] => stdClass Object
(
[iId] => 97
[sName] => Clothing & Accessories
[sDescription] => Clothing & Accessories
[iAdult] => 0
)

[1] => stdClass Object
(
[iId] => 61
[sName] => Computers & Software
[sDescription] => Computers & Software
[iAdult] => 0
)

[2] => stdClass Object
(
[iId] => 4
[sName] => Electronics
[sDescription] => Electronics
[iAdult] => 0
[oCategoryTree] => stdClass Object
(
[oCategory] => Array
(
[0] => stdClass Object
(
[iId] => 5
[sName] => Audio Equipment
[iParentId] => 4
[sDescription] => Audio Equipment
[iAdult] => 0
)

[1] => stdClass Object
(
[iId] => 6
[sName] => Home Entertainment
[iParentId] => 4
[sDescription] => Home Entertainment
[iAdult] => 0
)

[2] => stdClass Object
(
[iId] => 7
[sName] => Photography
[iParentId] => 4
[sDescription] => Photography
[iAdult] => 0
)

[3] => stdClass Object
(
[iId] => 8
[sName] => Portable Audio
[iParentId] => 4
[sDescription] => Portable Audio
[iAdult] => 0
[oCategoryTree] => stdClass Object
(
[oCategory] => Array
(
[0] => stdClass Object
(
[iId] => 35
[sName] => Accessories
[iParentId] => 8
[sDescription] => Accessories
[iAdult] => 0
)

[1] => stdClass Object
(
[iId] => 618
[sName] => Batteries
[iParentId] => 8
[sDescription] => Batteries
[iAdult] => 0
)

[2] => stdClass Object
(
[iId] => 40
[sName] => MP3 Players
[iParentId] => 8
[sDescription] => MP3 Players
[iAdult] => 0
)

[3] => stdClass Object
(
[iId] => 38
[sName] => Portable CD Players
[iParentId] => 8
[sDescription] => Portable CD Players
[iAdult] => 0
)

[4] => stdClass Object
(
[iId] => 42
[sName] => Portable Radios
[iParentId] => 8
[sDescription] => Portable Radios
[iAdult] => 0
)

)

)

)

[4] => stdClass Object
(
[iId] => 9
[sName] => Televisions
[iParentId] => 4
[sDescription] => Televisions
[iAdult] => 0
)

)
)
)

[3] => stdClass Object
(
[iId] => 634
[sName] => Entertainment
[sDescription] => Entertainment
[iAdult] => 0
)
)
)
)
[/text]

Thanks

Scary

Re: Displaying SOAP requesxt output

Posted: Mon Oct 21, 2013 12:35 pm
by requinix
Make a function that does that foreach you have (rather than just put the foreach inline with your code). Then you can make it call itself on the $details->oCategoryTree (if present) to display the children.

Re: Displaying SOAP requesxt output

Posted: Tue Oct 22, 2013 5:35 am
by scary
Many thanks for that. What has me stumped at the moment is testing for the existence of children of a parent. I've tried various combination of is_array and is_object in an if statement. I get Undefined property messages etc on parents without children. Any ideas on how test for the existence of children?

Thanks Scary

Re: Displaying SOAP requesxt output

Posted: Tue Oct 22, 2013 1:02 pm
by requinix

Code: Select all

isset($details->oCategoryTree)