获取数组中重复次数最多的值 [英] Getting the most repeated values in an array
本文介绍了获取数组中重复次数最多的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的数字数组:
I have an array of numbers like this:
$array = array(1,1,1,4,3,1);
如何获得最多重复值的计数?
How do I get the count of most repeated value?
推荐答案
这应该有效:
$count=array_count_values($array);//Counts the values in the array, returns associatve array
arsort($count);//Sort it from highest to lowest
$keys=array_keys($count);//Split the array so we can find the most occuring key
echo "The most occuring value is $keys[0][1] with $keys[0][0] occurences."
这篇关于获取数组中重复次数最多的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文