Php Twitter API用户/按关注者计数的搜索顺序

Php Twitter API用户/按关注者计数的搜索顺序,php,json,twitter,Php,Json,Twitter,使用以下对twitter API的调用,我可以返回一个带有搜索参数(例如“farming”)的twitter帐户列表 然而,结果似乎毫无条理。是否有一种方法可以按[followers\u count]对结果进行排序?如果没有,是否有人知道默认排序是什么?是的,可以按followers count排序。请尝试以下代码 $json = "< YOUR TWITTER JSON RESULT RESPONSE >"; $result = json_decode($json, true);

使用以下对twitter API的调用,我可以返回一个带有搜索参数(例如“farming”)的twitter帐户列表


然而,结果似乎毫无条理。是否有一种方法可以按
[followers\u count]
对结果进行排序?如果没有,是否有人知道默认排序是什么?

是的,可以按followers count排序。请尝试以下代码

$json = "< YOUR TWITTER JSON RESULT RESPONSE >";
$result = json_decode($json, true);

function sortByOrder($a, $b) {
    return $a['followers_count'] - $b['followers_count'];// asc
    // return $b['followers_count'] - $a['followers_count'];// desc
}

usort($result, 'sortByOrder');

echo '<pre>'.print_r($result,true).'</pre>'; //ordered array
$json=“”;
$result=json_decode($json,true);
功能排序器($a,$b){
返回$a['followers\u count']-$b['followers\u count'];//asc
//返回$b['followers_count']-$a['followers_count'];//说明
}
usort($result,'sortByOrder');
回显“”。打印($result,true)。“”//有序数组

您可以选择使用ASC或DESC顺序。

不幸的是,这只会对当前请求的页面顺序进行排序。i、 e.page=2将返回一组新的结果,其跟随者计数高于page=1的最后一个结果
$json = "< YOUR TWITTER JSON RESULT RESPONSE >";
$result = json_decode($json, true);

function sortByOrder($a, $b) {
    return $a['followers_count'] - $b['followers_count'];// asc
    // return $b['followers_count'] - $a['followers_count'];// desc
}

usort($result, 'sortByOrder');

echo '<pre>'.print_r($result,true).'</pre>'; //ordered array