Php 在多维数组中查找重复值

Php 在多维数组中查找重复值,php,arrays,multidimensional-array,Php,Arrays,Multidimensional Array,我有一个数组,看起来像这样: Array ( [0] => Array ( [0] => Model2345 [1] => John Doe [2] => SN1234 ) [1] => Array ( [0] => Model2345 [1] => John Doe

我有一个数组,看起来像这样:

Array
(
    [0] => Array
        (
            [0] => Model2345
            [1] => John Doe
            [2] => SN1234
        )

    [1] => Array
        (
            [0] => Model2345
            [1] => John Doe
            [2] => SN3456
        )

    [2] => Array
        (
            [0] => Model1234
            [1] => Jane Doe
            [2] => SN3456
        )
)

我想有一种方法来检查php中键[1](John Doe/Jane Doe键)和[2](SNxxxx键)的重复值,但忽略键[0]的重复值。如何做到这一点?

这个问题已经得到了回答。以下是该问题开头的代码

它使用
数组_intersect()
函数

<?php
$array = array(array("test data","testing data"), array("new data","test data"), array("another data", "test data", "unique data"));
$result = array();

$first = $array[0];
for($i=1; $i<count($array); $i++)
{
    $result = array_intersect ($first, $array[$i]);
    $first = $result;
}
print_r($result);
?>

输出:

数组([0]=>测试数据)

试试这个:

$array = your_array();

$current = current($array);
foreach($array as $key => $val){
 $duplicate[$key] = array_intersect($current, $val);
}

echo($duplicate);

您可以迭代数组并检查该特定索引是否存在重复使用
数组_intersect()
。我在数组中尝试了此操作,但即使存在明显的重复,也会得到一个空结果。这是因为您的示例使用的是整数而不是字符串吗?我测试了代码,它也适用于字符串。我已经用适合我的代码更新了代码。当然,这只有在所有三个子数组中都有一个公共值时才有效,这意味着它将为示例数组显示空结果。你是在寻找一个能捕捉到哪怕是一个重复的数组,还是只捕捉所有数组的数组?啊,我明白了,所以这对我不起作用。我需要抓住哪怕是一个重复。它似乎很好,谢谢!这几乎可以工作,但无论是否有重复,它总是打印第一个数组。
<?php

$Contacts = [
  [
    'name' => 'name 1',
    'phone' => '12341234',
    'email' => 'test@web.com'
  ],
  [
    'name' => 'name 1',
    'phone' => '12341234',
    'email' => 'test@web.com'
  ],
  [
    'name' => 'name 3',
    'phone' => '4322342',
    'email' => 'test@web1.com'
  ],
  [
    'name' => 'name 4',
    'phone' => '1234123423',
    'email' => 'test@web1.com'
  ],
  [
    'name' => 'name 5',
    'phone' => '12341266634',
    'email' => 'test@eqweqwweb.com'
  ],
];

$start = microtime(true);   

    // function CheckDuplicteContacts($Contacts)
    // {
        if(count($Contacts) == 1){
            return $validator = true;
        } else {
            $DuplicateLines = [];
            foreach($Contacts as $CurrentKey => $Contact)
            {
                foreach($Contacts as $SearchKey => $SearchContact)
                {
                    
                    if(
                        (
                            ($SearchContact["name"] == $Contact["name"]) &&
                            ($SearchContact["email"] == $Contact["email"]) &&
                            ($SearchContact["phone"] == $Contact["phone"])
                        )
                        && 
                        ($SearchKey != $CurrentKey))
                    {
                        array_push($DuplicateLines,$CurrentKey + 1);
                    }
                }
            }
            $validator = empty($DuplicateLines) ? true : $DuplicateLines;

        }
  //  }
    
 
var_dump($validator);

echo (microtime(true) -$start)*100;