2013-07-05 32 views
0

我有2門陣列(這可能是多個陣列),並需要找到出現的最值:紀錄在陣列

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

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

所以我試圖找到PD0001,有什麼建議?

+1

出現在大多數數組或出現在所有陣列上的大部分時間結合起來呢? –

+2

查看['array_count_values'](http://php.net/manual/en/function.array-count-values.php):-) –

+0

使用'array_merge'和'array_count_values'。 – Barmar

回答

1

這裏有一個腳本,它可以爲你做的:

// 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); 
+0

好人,謝謝你。 – woodscreative