Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从std对象获取值_Php_Facebook Graph Api - Fatal编程技术网

Php 从std对象获取值

Php 从std对象获取值,php,facebook-graph-api,Php,Facebook Graph Api,有人能帮我解决这个问题吗:我正试图用$someVar->data->values->value来回显“value”中的值,但没有返回任何内容。我还尝试了$someVar->values->value。我是一个PHP新手,所以如果这是一个愚蠢的问题,请原谅我 stdClass Object ( [data] => Array ( [0] => stdClass Object ( [id] => 123/insights/post_impressions_organic_uni

有人能帮我解决这个问题吗:我正试图用
$someVar->data->values->value
来回显“value”中的值,但没有返回任何内容。我还尝试了
$someVar->values->value
。我是一个PHP新手,所以如果这是一个愚蠢的问题,请原谅我

 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= ) )

代码是Facebook Graph API的JSON解码输出。

那里的对象中有数组,试试这个

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

如果您在打印对象周围放置
标记,它也会对您有所帮助,它会对打印对象进行格式化,以便您可以轻松查看结构。

对象中有数组,请尝试此操作

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

如果您在打印对象周围放置
标记,它也会帮助您,它会对打印对象进行格式化,以便您可以轻松查看结构。

它就像一个魔咒!很抱歉,格式错误的代码。再次感谢你,你真的帮了我很多忙!它就像一个符咒!很抱歉,格式错误的代码。再次感谢你,你真的帮了我很多忙!
$someVar->data[0]->values[0]->value