我正在加载一系列标签,并希望按人气排序,其中应首先列出最受欢迎的单词,依此类推。 怎么做?
PHP:
function addTags($jsonArray)
{
$output = array();
foreach($jsonArray['response']['posts'] as $post)
{
foreach($post['tags'] as $tag)
{
$output[] = $tag;
}
}
return $output;
}
JSON标记示例:
["mostpopular","single","mostpopular","foo","foo","mostpopular","bar"]
答案 0 :(得分:0)
检查这有帮助
$jsonArray = array ("mostpopular","single","mostpopular","foo","foo","mostpopular","bar");
$jsonresult = array_count_values($jsonArray);
echo '<pre>'; print_r($jsonresult);echo '</pre>';
//Array ( [mostpopular] => 3 [single] => 1 [foo] => 2 [bar] => 1)
$jsonsort = arsort($jsonresult);
echo '<pre>'; print_r($jsonresult);echo '</pre>';
// Array ([mostpopular] => 3 [foo] => 2 [single] => 1 [bar] => 1)