i have this multidimensional array
[
['name' => 'test1', 'number' => '9999'],
['name' => 'test2', 'number' => '9999'],
['name' => 'test3', 'number' => '5555'],
['name' => 'test4', 'number' => '6666'],
['name' => 'test5', 'number' => '6666'],
['name' => 'test6', 'number' => '6666'],
]
my plan is to get it to where the duplicates are pointed out except for the first instance
[
['name' => 'test1', 'number' => '9999'],
['name' => 'test2', 'number' => '9999', 'duplicate' => 'yes'],
['name' => 'test3', 'number' => '5555'],
['name' => 'test4', 'number' => '6666'],
['name' => 'test5', 'number' => '6666', 'duplicate' => 'yes'],
['name' => 'test6', 'number' => '6666', 'duplicate' => 'yes'],
]
notice that the first duplicate is excluded and only any other duplicates are marked as duplicates
if it helps, i have a separate array that i run array_count_values on, and get
array (size=3)
9999 => int 2
5555 => int 1
6666 => int 3
so i know how many duplicates are for each number
foreach initial array i could test if the numbers match the ones from the array_count_values array and see if the count > 1 then mark them as duplicates, but im not sure how to exclude the first dup instance
any ideas?
$array = [
['name' => 'test1', 'number' => '9999'],
['name' => 'test2', 'number' => '9999'],
['name' => 'test3', 'number' => '5555'],
['name' => 'test4', 'number' => '6666'],
['name' => 'test5', 'number' => '6666'],
['name' => 'test6', 'number' => '6666'],
];
$second = [
'9999' => 2,
'5555' => 1,
'6666' => 3,
];
foreach($array as $k => $data) {
foreach($second as $num => $key) {
if($key > 1) {
if($data['number'] == $num) {
$array[$k]['duplicate'] = 'yes';
}
}
}
}
var_dump($array);