Well, that's why the daily twitter list is 20 trends. Let's say I want to get the 7th trend in the list. Here is my long way to do this ...
$trendArray = 7;
$jsonurl = "http://search.twitter.com/trends/daily.json";
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json);
$allTrends = $json_output->trends;
foreach ( $json_output->trends as $trendslist ) {
foreach ( $trendslist as $trend ) {
$loop += 1;
if ($loop == $trendArray) {
$theTrend = $trend->name;
break;
}
}
break;
}
echo $theTrend;
I suspect I'm confusing objects and arrays, but I'm sure there is a much easier way to do this than with the two for each loop, because
$theTrend = $json_output->trends[6]->name;
Gives me this error:
Fatal error: Cannot use object of type stdClass as array
Thank you for your help!
source
share