Georg
Georg

Reputation: 648

Getting value from std Object

Can anyone please help me out with that one: I'm trying to echo the value from "value" with $someVar->data->values->value but doesn't return anything. I also tried $someVar->values->value. I'm a PHP newbie so please forgive me if that is a silly question.

 stdClass Object ( [data] => Array ( [0] => stdClass Object ( [id] => 
123/insights/post_impressions_organic_unique/lifetime [name] => 
post_impressions_organic_unique [period] => lifetime [values] => Array ( [0] => 
stdClass Object ( [value] => 286 ) ) [title] => Lifetime Post Organic Reach [description] => Lifetime The number of people who saw your Page post in News Feed or ticker, or on your Page's Wall. (Unique Users) ) ) [paging] => stdClass Object ( [previous] => 
https://graph.facebook.com/123/insights/post_impressions_organic_unique&access_token=[next] => https://graph.facebook.com/123/insights/post_impressions_organic_unique&access_token= ) )

The code is a JSON decoded output from the Facebook Graph API.

Upvotes: 0

Views: 1937

Answers (2)

Mikhail
Mikhail

Reputation: 2562

$someVar->data[0]->values[0]->value

Upvotes: 0

MrCode
MrCode

Reputation: 64526

There are arrays within objects there, try this.

foreach($someVar->data as $arr1)
{
    foreach($arr1->values as $obj)
    {
        echo 'Value: ' . $obj->value;
    }
}

Also it will help you if you put <pre> tags around a printed object, it formats it so you can easily see the structure.

Upvotes: 3

Related Questions