簡體   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