DotDragnet
May 24, 2012, 08:15:31 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Mobile users - Our forum is Tapatalk enabled. http://www.tapatalk.com/
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: convert to an array?  (Read 144 times)
SLEE
Hero Member
*****
Posts: 824



View Profile WWW Awards
« on: November 14, 2011, 08:56:14 PM »

I am working with an job API and I was almost about ready to tidy things up and make it live until i tested it and found out that when I was doing a search and only receiving one job the code broke.

When searching and getting a result with more than 1 job everything is fine and here is the data i get in the array:

stdClass Object ( [return] => stdClass Object ( [dtos] => Array (
  • => stdClass Object ( [address] => stdClass Object ( [address1] => [city] => Alexandria [countryID] => 1

Then when I only get 1 job returned i get this:

stdClass Object ( [return] => stdClass Object ( [dtos] => stdClass Object ( [address] => stdClass Object ( [address1] => [city] => Alexandria [countryID] => 1

you can see the dtos is an array on the multiple return but a string if there is only 1

Currently I am using a for each loop to get the data:

Code:
<?php foreach($findResult->return->dtos as $value):?>

but is there a way to either convert the string to an array or another way to read in the data from the dtos?
Logged

SLEE - still the most confusing ddner...

Follow me on Twitter
SLEE
Hero Member
*****
Posts: 824



View Profile WWW Awards
« Reply #1 on: November 14, 2011, 10:58:45 PM »

managed to figure it out myself.
I didn't know you could use break to stop a forloop

I managed to use that and put the string into the $value if the original query is not an array.
Logged

SLEE - still the most confusing ddner...

Follow me on Twitter
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!