I have an multidimensional array:
Array
(
[0] => Array
(
[a] => 1
[b] => 2
[c] => 3
[d] => 4
)
[1] => Array
(
[a] => 1
[b] => 5
[c] => 3
[d] => 4
)
[2] => Array
(
[a] => 1
[b] => 2
[c] => 3
[d] => 4
)
)
Look at the first index (or zero) and third index (number two index), the values in a,b,c,d is equal 1,2,3,4. Assuming that the array is equal, or no different of them; my question is, how can I catch the array which equal, my purpose to show users about the value input duplicate,
I have already been using array_unique
. This is the result :
Array
(
[0] => Array
(
[a] => 1
[b] => 2
[c] => 3
[d] => 4
)
[1] => Array
(
[a] => 1
[b] => 5
[c] => 3
[d] => 4
)
)
But I just want to get duplicate data, not remove the data duplicate.
// first : get all data, if the data same / duplicate take only one data
$unique = array_unique($data, SORT_REGULAR);
// then, get the data which duplicate with
$diffCellUniq = array_diff_key($data, $unique);
// so print the result
print_r($diffCellUniq); exit;
Array
(
[2] => Array
(
[a] => 1
[b] => 2
[c] => 3
[d] => 4
)
)