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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.