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

发布于 2024-10-26 19:57:15 字数 832 浏览 0 评论 0原文

我正在尝试获取对象中数组的总数。

我正在使用 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']));

,我再次只需要获取数组值。比如上面的about例子中的3。

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

谢谢

I am trying to get the total for the Array in the Object.

I am using print_r to get the following to see whats in it.

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

here is my code to get the information

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

Again I just need to get the Array value. Such as 3 in the about example above.

I am very new to this. Any advice will help.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神经大条 2024-11-02 19:57:15

尝试:

$c = count($movies->data)

Try:

$c = count($movies->data)
轻拂→两袖风尘 2024-11-02 19:57:15
    //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;

只需调用变量键的名称

    //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;

just call the name of the variable key

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文