I realize there are quite a few questions of this nature, but I have not been able to solve my issue using the other posts, so I was hoping someone here may be able to help me out.
I have an object I'm getting back from Yahoo local search API. I have passed the results into json_decode()
and saved the results to $yahoo_json_decoded
. I can get data from the results using a for loop and doing the following:
echo 'Name: ' . $yahoo_json_decoded->ResultSet->Result[$i]->Title . '<br />' ;
But I can't seem to be able to make the foreach work:
foreach($yahoo_json_decoded->ResultSet as $res=>$variable)
{
$listingID = $yahoo_json_decoded->ResultSet[$res]->id ;
echo $listingID;
}
I could just loop the data and move on, but I really want to understand why the foreach
isn't working.
Thanks (show mercy)
Kirk
Based on $yahoo_json_decoded->ResultSet->Result[$i]->Title
which you say works:
foreach($yahoo_json_decoded->ResultSet->Result as $index => $result)
{
$listingID = $result->id ;
echo $listingID;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With