php - Getting data from Yelp API


I'm starting to look into Yelp API. When I send a search request I get a data returned in an array $response. So If I output it like this

echo '<pre>';
echo '</pre>';

I see results in the following format

stdClass Object
    [message] => stdClass Object
            [text] => OK
            [code] => 0
            [version] => 1.1.1

    [businesses] => Array
            [0] => stdClass Object
                    [rating_img_url] =>
                    [country_code] => US

So, let's say I want to get the country code, shouldn't I be able to get it with something like?

echo $response['businesses'][0]->country_code;

I'm not getting any results. What am I missing?




echo $response->businesses[0]->country_code;

businesses is a property, not an array element.

Everything belowstdClass Object are properties.

Everything below=> Array are Array Elements.

Let me guess,$response = json_decode(...); ?

You can tell this function to return associative arrays instead of objects by putting up the second parametertrue:

$response = json_decode(..., true);

Then the values would be in:

echo $response['businesses'][0]['country_code'];

People are also looking for solutions to the problem: php - Creating Custom Latest Post Shortcode Including Featured image


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.