There is a similar question which checks to see whether a given string value exists multiple times within an array.
However, I have an array of arrays. Example:
$testing = [
1 => ['a' => '', 'b' => '2020-12-04 13:15:36'],
2 => ['a' => '', 'b' => '2020-12-04 17:15:00'],
3 => ['a' => '', 'b' => '2021-01-04 17:15:00'],
2 => ['a' => '', 'b' => '2021-01-04 17:15:00'],
];
The array $testing contains two elements using the key '2', but the value-parts of each of those elements differs.
If I use the approach in the linked example (using array_keys
) it reports that each element exists only once in the array; ie. it notices that the value-parts differ and so counts them as unique elements within $testing.
How can I go about testing each array element to check whether the element's key-part exists multiple times in $testing?
That is, I want 1 and 3 to report they are unique within $testing, but 2 to report that it is duplicate - it exists multiple times within $testing (even though the value-part differs in each instance).