简体   繁体   English

在重复值最多的数组中显示前5个值

[英]Show First 5 value in an array that has the most duplicates values

I want to show first five array value who has most duplicate value like in tags we show the popular tags like that now what i have done till now is i am getting all tags from database as you can see below 我想显示前五个具有最多重复值的数组值,就像在标签中一样,我们在显示流行的标签,就像现在那样,到目前为止,我正在从数据库中获取所有标签,如下所示

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

and after that exploding it into array and printing it in li like below 然后将其分解为数组并以如下形式打印出来

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

  $tagsss = array_count_values($tag);

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

and the result is showing like this 结果显示像这样

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 )

Now in all this entry i just want to show first five value who have the most duplicate value just like popular tags 现在,在所有此条目中,我只想显示前五个值,它们与重复使用的标签一样,具有最重复的值

Instead of using PHP function I'll get those tags from MySQL only from query like as 我将不使用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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM