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
)
)
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.
It utilizes the array_intersect()
function.
<?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);
?>
OUTPUT:
Array ( [0] => test data )
Try this:
$array = your_array();
$current = current($array);
foreach($array as $key => $val){
$duplicate[$key] = array_intersect($current, $val);
}
echo($duplicate);