从对象中获取数据 [英] fetch data from an object

查看:71
本文介绍了从对象中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此代码从用户的 twitter 帐户中获取数据

I am trying to fetch data from user's twitter account with this code

$user_info = $twitteroauth->get('account/verify_credentials');

我在一个对象中得到一个很长的值

i get a very long value in an object

stdClass Object
(
    [id] => 2999359418
    [id_str] => 2999359418
    [name] => ABC
    [screen_name] => ABC9
    [location] => 
    [profile_location] => 
    [description] => XYZ
    [url] => 
    [entities] => stdClass Object
        (
            [description] => stdClass Object
                (
                    [urls] => Array
                        (
                        )

                )

        )

    [protected] => 
    [followers_count] => 0
    [friends_count] => 0
    [listed_count] => 0
    [created_at] => Wed Jan 28 12:17:43 +0000 2015
)

我希望从中检索数据.

例如.我试图通过此代码检索描述但做错了,因为我没有得到结果.谁能告诉我如何获取数据

eg. i tried to retrieve description by this code but did it wrong, coz i did not get the result. can anyone please tell how to fetch the data

推荐答案

信息不是array,而是object.您可以通过以下方式访问数据:

The information is not an array, but an object. You can access the data by the following:

$info = $user_info->description;

您可以重复此操作以进一步向下链,例如:

You can repeat this by to go further down the chain such as:

$user_info->entities->description

这篇关于从对象中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆