如何获取stdClass对象的数组总数?

时间:2011-03-28 18:18:48

标签: php arrays json facebook

我试图在Object中获取Array的总数。

我正在使用print_r来获取以下内容以查看其中的内容。

stdClass Object ( [data] => Array ( [0] => stdClass Object ( [name] => The Drift Bible [category] => Movie [id] => 227431881228 [created_time] => 2011-02-27T21:41:04+0000 ) [1] => stdClass Object ( [name] => Shooter [category] => Movie [id] => 109671005718938 [created_time] => 2011-02-16T09:18:29+0000 ) [2] => stdClass Object ( [name] => Tron [category] => Movie [id] => 99792857339 [created_time] => 2010-11-29T03:18:06+0000 ))

这是获取信息的代码

$movies = json_decode(file_get_contents('https://graph.facebook.com/me/movies?' 
.'format=json&access_token=' . $session['access_token']));

我只需要获取Array值。例如上面的例子中的3个。

我对此很新。任何建议都会有所帮助。

由于

2 个答案:

答案 0 :(得分:1)

尝试:

$c = count($movies->data)

答案 1 :(得分:1)

    //creating facebook_id from facebook_url
$sRequestUrl = 'http://graph'.strstr($a_data['contact_data']['facebook'], '.facebook');

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => $sRequestUrl
        ));
        $res = curl_exec($curl);
        curl_close($curl);
        $res = json_decode($res);

        id = $res->id;
            about = $res->about;

只需调用变量键的名称

即可