本文介绍了在多维数组中查找重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个看起来与此类似的数组:
I have an array that looks similar to this:
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]的重复值。
I want to have a way to check for duplicate values for keys [1] (the John Doe/Jane Doe key) and [2] (the SNxxxx key) in php, but ignore duplicates for key [0]. How can this be accomplished?
推荐答案
此问题已得到回答中的代码。
This question has already been answered here. The following is the code from the accepted answer of that question.
它利用 array_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);
?>
输出:
这篇关于在多维数组中查找重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!