hobojjr Posted October 12, 2008 Share Posted October 12, 2008 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. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted October 12, 2008 Share Posted October 12, 2008 have you tried.. if(!is_array($object)) { $object = array($object); } or are you saying the service could return a 2d array or a 3d array and you need to know how to differentiate between the two? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.