Displaying SOAP requesxt output

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scary
Forum Newbie
Posts: 2
Joined: Mon Oct 21, 2013 11:41 am

Displaying SOAP requesxt output

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Displaying SOAP requesxt output

Post 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.
scary
Forum Newbie
Posts: 2
Joined: Mon Oct 21, 2013 11:41 am

Re: Displaying SOAP requesxt output

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Displaying SOAP requesxt output

Post by requinix »

Code: Select all

isset($details->oCategoryTree)
Post Reply