$input = array(1,1,2,3,2,1,1);
$c = array_count_values($input);
$val = array_search(max($c), $c)
$count =
按预期返回1(最常见)。我怎么知道它在数组中出现了多少次?有许多类似的问题,但没有一个人对找出计数感兴趣。
echo $val. "ccours". $count . "times";
你确定你正确地解释了结果吗?因为函数应该做你所需要的。从手册:
<?php
$array = array(1, "hello", 1, "world", "hello");
print_r(array_count_values($array));
?>
结果应该是:
Array
(
[1] => 2
[hello] => 2
[world] => 1
)