php - 如何获取数组的对象值

标签 php arrays arrayobject

我是 php 新手,正在尝试从 twitter api 读取文本描述。我的数组如下所示:

Array
(
    [0] => stdClass Object
        (
            [created_at] => Thu Oct 03 14:50:55 +0000 2013
            [id] => 3.85778998506E+17
            [id_str] => 385778998506033154
            [text] => We tested live-tweeting with @MLB to see if teams could boost follower engagement and their Twitter audience: https://t.co/XPhHmVDNxJ
            [source] => TweetDeck
            [truncated] => 
            [in_reply_to_status_id] => 
            [in_reply_to_status_id_str] => 
            [in_reply_to_user_id] => 
            [in_reply_to_user_id_str] => 
            [in_reply_to_screen_name] => 
            [user] => stdClass Object
                (
                    [id] => 783214
                    [id_str] => 783214
                    [name] => Twitter
                    [screen_name] => twitter
                    [location] => San Francisco, CA
                    [description] => Your official source for news, updates and tips from Twitter, Inc.
                    [url] => http://t.co/5iRhy7wTgu
                    [entities] => stdClass Object

我尝试这样阅读,但无法打印任何内容 echo $tweets->text;

最佳答案

试试这个:

echo $tweets[0]->text;
echo $tweets[0]->user->description;

我希望这对您有帮助:)

关于php - 如何获取数组的对象值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19164570/

相关文章:

java - 如何将数组写入具有列分隔值的文件

PHP 数组和 ArrayObject

php - 为什么 PHP 文件不用于(自定义)CSS 和 JS?

php - php orm 学说如何获取对象及其相关连接

php - is_array() 的区别

jquery - 为什么 jQuery.append(new Array(3).fill($ ('<div>' ,{text :'hello' }))) 仅附加一项?

php - 通过 Google/Gmail 而不是从我的服务器发送电子邮件的优缺点

java - 通过未经检查的类型转换在 Java 中创建通用数组

java - 如何从 Java 中的对象 ArrayList 获取 ArrayList 值?

javascript - 通过唯一属性组合单个对象数组