[英]Printing all values in array
I have the following code that prints out the first value in the array (Twitter post): 我有以下代码可以打印出数组中的第一个值(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>';
However, I want to print out all values in the array. 但是,我想打印出数组中的所有值。 I have tried using below method as stated here: http://php.net/manual/en/function.array-values.php
我已经尝试使用下面所述的方法: http : //php.net/manual/en/function.array-values.php
array_values($my_tweets)
But that returns the following: "Trying to get property of non-object" 但这返回以下内容:“试图获取非对象的属性”
What exactly am I doing wrong? 我到底在做什么错?
Thank you. 谢谢。
Try this 尝试这个
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);
OR 要么
print_r($my_tweets);
You can also loop 您也可以循环
foreach($my_tweets as $tweet){
echo $tweet;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.