2016-07-08 56 views
0

我想顯示具有最多重複值的前五個數組值,比如在標記中我們顯示這樣的流行標記現在我所做的直到現在我正在從數據庫中的所有的標籤,你可以看到下面顯示具有最多重複值的數組中的前5個值

SMS Gateway,sms service,bulk sms,bulk sms, Courier Management Software Development, Customised software solutions, domain registration, Ecommerce website designing company, matrimony website developer, seo tutorials bhopal, Web-site designing, redesigning, updationsSMS Gateway,sms service,bulk sms 

,之後爆炸成陣列進行打印李象下面

$tag = explode(",", $tags); 

    $tagsss = array_count_values($tag); 

    foreach($tagsss as $key => $value) { 
     echo "<li>$key ($value)</li>"; 
    } 

,其結果顯示這樣

SMS Gateway (1)sms service (2)bulk sms (3) Courier Management Software Development (1) Customised software solutions (1) domain registration (1) Ecommerce website designing company (1) matrimony website developer (1) seo tutorials bhopal (1) Web-site designing (1) redesigning (1) updationsSMS Gateway (1) 

現在這一切進入我只是想顯示前五個值誰擁有最重複的值就像熱門的標籤

+3

'arsort($ tagsss); $ tagsss = array_slice($ tagsss,0,5);' – splash58

+0

顯示你預期的輸出 –

+1

非常感謝@ splash58這正是我想要的 –

回答

1

而不是使用PHP函數,我只能從查詢從MySQL獲得這些標記等作爲

SELECT CONCAT(tag_name, " ", COUNT(tag_name)) AS tags 
FROM tags_table 
GROUP BY tag_name 
ORDER BY COUNT(tag_name) DESC 
LIMIT 5