我想显示前五个数组值最重复的值,就像在标签中我们显示流行的标签,就像现在我所做的是我从数据库中获取所有标签,如下所示
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
然后将其爆炸成数组并将其打印在li中,如下所示
$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 )
现在在所有这些条目中,我只想显示前五个价值最重复的值,就像流行的标签一样
答案 0 :(得分: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