0

我有一个这样的数组:

[input] => Array (
    [0] => Array ( [val1] => 111 [val2] => 222 [val3] => 333 [day] => 444 )          
    [1] => Array ( [val1] => 111 [val2] => 221 [val3] => 333 [day] => 444 ) 
    [2] => Array ( [val1] => 111 [val2] => 223 [val3] => 333 [day] => 444 ) 
    [3] => Array ( [val1] => 111 [val2] => 224 [val3] => 333 [day] => 444 )
    [4] => Array ( [val1] => 111 [val2] => 222 [val3] => 333 [day] => 444 ) 
           ) 

我只想检查数组中的前 2 个值(val1 和 val2)是否与另一个数组相同。就像上面例子中的 input[0] 和 input[4] 。我如何在 php 中执行此操作?

我不想删除重复的数组,我只是返回重复的值以供进一步使用。

谢谢

4

1 回答 1

0

您只需要存储这些键的数组:

$uniq = array();
foreach($input as $v) {
    $key = $v['val1'] . '-' . $v['val2'];
    if (!isset($uniq[$key]))
        $uniq[$key] = 0;
    else
        $uniq[$key]++;
}
print_r(array_filter($uniq));
于 2012-09-22T16:29:16.160 回答