[Solved] How to search duplicate value in array


You can do it with simple for loop :

$arr = array(["id" => 7, "a" => ""], ["id" => 6, "a" => "AAA"], ["id" => 4, "a" => "AAA"]);

$ans = [];    
foreach($arr as $elem)
        $ans[$elem["a"]][] = $elem["id"];

This will output associative array with the “a” value as keys – if you only want to group them you can use array_values.

Output:

Array
(
    [] => Array
        (
            [0] => 7
        )
    [AAA] => Array
        (
            [0] => 6
            [1] => 4
        )
)

1

solved How to search duplicate value in array