Jump to content

[PHP + SOAP] problem with arrays


hobojjr

Recommended Posts

Hi,

 

I have a webservice that returns array of objects. The problem is that when there is only one element in the array then the SOAP message does not return an "array". So when I try to output the returned data in foreach I get an error. Casting only works if the returned "array" is a simple type (string, int, etc) but if it is an object array then casting will turn the fields of the object into elements of the array.

 

Example:

Service returns array of users - each user has two fields: name and email.

 

When there is more than one user returned then foreach works fine:

foreach($users as $user)...

 

But when there is only one user then foreach will throw and error because $users is not an array and casting $users to array will turn user fields in to array elements.

 

I hope you understand what I am saying.

 

 

Link to comment
https://forums.phpfreaks.com/topic/128092-php-soap-problem-with-arrays/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.