繁体   English   中英

打印数组中的所有值

[英]Printing all values in array

我有以下代码可以打印出数组中的第一个值(Twitter帖子):

$connection = new TwitterOAuth($twitter_customer_key, $twitter_customer_secret, $twitter_access_token, $twitter_access_token_secret);

$my_tweets = $connection->get('statuses/user_timeline', array('screen_name' => 'xxx', 'count' => 10));

echo '<div class="tweets">';
if(isset($my_tweets->errors))
{           
echo 'Error :'. $my_tweets->errors[0]->code. ' - '. $my_tweets->errors[0]->message;
}else{
echo makeClickableLinks($my_tweets[0]    ->text);
}
echo '</div>';

但是,我想打印出数组中的所有值。 我已经尝试使用下面所述的方法: http : //php.net/manual/en/function.array-values.php

array_values($my_tweets)

但这返回以下内容:“试图获取非对象的属性”

我到底在做什么错?

谢谢。

尝试这个

    for($i = 0; $i<=count($my_tweets) -1; $i++){
        if(isset($my_tweets[$i]->errors)){                   
            echo 'Error :'. $my_tweets->errors[$i]->code. ' - '. $my_tweets->errors[$i]->message;
        } else{
            echo makeClickableLinks($my_tweets[$i]->text);
        }
    }
var_dump($my_tweets);

要么

print_r($my_tweets);

您也可以循环

foreach($my_tweets as $tweet){
    echo $tweet;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM