Kode Kite Kode Kite - 3 months ago 6
PHP Question

how can I get the duplicate multidimensional array in php

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 has 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

what should I do?

thanks before.

[CASE CLOSED]

// 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
)

)

Answer

// 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
        )

)