2016-03-06 171 views
0

所有值我有下面的代碼,在陣列(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) 

但是,返回如下::我一直在使用下面的方法說明這裏嘗試「試圖獲得非對象的財產」

我究竟做錯了什麼?

謝謝。

回答

1

試試這個

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); 
     } 
    } 
+0

感謝您的建議。我得到以下錯誤:解析錯誤:語法錯誤,意想不到的'其他'(T_ELSE)在C:\ wamp64 \ www \ index.php 59行 – user2329190

+1

是的,我寫錯了代碼。我已經編輯 –

+0

謝謝,你的建議工作。 – user2329190

0
var_dump($my_tweets); 

OR

print_r($my_tweets); 

您還可以循環

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