Php 数组中的引用

Php 数组中的引用,php,arrays,Php,Arrays,我有2个数组(可能更多个数组),需要找到显示最多的值: array(2) { [0]=> string(6) "PD0001" [1]=> string(6) "PD0002" } array(2) { [0]=> string(6) "PD0001" [1]=> string(6) "PD0003" } 因此,我正在尝试查找PD0001,有什么建议吗?这里有一个脚本可以为您提供: // First merge the arrays together

我有2个数组(可能更多个数组),需要找到显示最多的值:

array(2) {
 [0]=>
 string(6) "PD0001"
 [1]=>
 string(6) "PD0002"
}

array(2) {
 [0]=>
 string(6) "PD0001"
 [1]=>
 string(6) "PD0003"
}

因此,我正在尝试查找PD0001,有什么建议吗?

这里有一个脚本可以为您提供:

// First merge the arrays together
$array = array_merge($array1, $array2);

// Get the array counts like this:
$counts = array_count_values($array);

// Sort the array so the first one has the highest count
arsort($counts);

// Get the first key:
reset($counts);
$maxElement = key($counts);

在大多数数组中出现或在所有组合的数组中出现次数最多?签出:-)使用
array\u merge
array\u count\u values
。我将数组合并到$compare中,然后使用$result=array\u count\u values($compare),然后按键对其进行索引,PD0001位于顶部,这是正确的。我如何获得$result[0]?好人,谢谢你。