PHP:如何找到最常用的数组键? [英] PHP: How to find most used array key?
本文介绍了PHP:如何找到最常用的数组键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我们说我有一个简单的一维数组,其中包含10到20个条目.有些会重复,我将如何找出最常使用的条目?喜欢.
Lets say I have a simple 1D array with 10-20 entries. Some will be duplicate, How would I find out which entry is used the most? like..
$code = Array("test" , "cat" , "test" , "this", "that", "then");
如何将测试"显示为最常用的条目?
How would I show "test" as the most used entry?
推荐答案
$code = Array("test" , "cat" , "test" , "this", "that", "then");
function array_most_common($input) {
$counted = array_count_values($input);
arsort($counted);
return(key($counted));
}
echo '<pre>';
print_r(array_most_common($code));
这篇关于PHP:如何找到最常用的数组键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文