Get a unique array

I have an array

    Array
    (
     [fbid] = Array
            (
                **[0] => 115637705237540
                [1] => 115637705237540**
                [2] => 111723238962320
                [3] => 111723248962319
                [4] => 112721842195793
                [5] => 112567698877874
                [6] => 111844022283575
                **[7] => 115637705237540**
                [8] => 111840252283952
                [9] => 109642909170353
            )

       [fb_parentid] = Array
            (
                [0] => 571228125
                [1] => 571228125
                [2] => 571228125
                [3] => 571228125
                [4] => 571228125
                [5] => 571228125
                [6] => 571228125
                [7] => 571228125
                [8] => 571228125
                [9] => 571228125
            )

)

Here 0, 1 and 7 are repeated. First I want to get duplicate indices (0,1,7). Secondly, I want to display one index. In the above example, only the 0th.

After that, I want to remove 1 and 7 from [fb_parentid] and [fbid]

Can you help me?

+3
source share
2 answers

You are looking for the array_unique function .

$new_array = array_unique($old_array);
+6
source

Try

$array = Array
    (
     "fbid" => Array
            (
                "0" => 115637705237540,
                "1" => 115637705237540,
                "2" => 111723238962320,
                "3" => 111723248962319,
                "4" => 112721842195793,
                "5" => 112567698877874,
                "6" => 111844022283575,
                "7" => 115637705237540,
                "8" => 111840252283952,
                "9" => 109642909170353
            ),

       "fb_parentid" => Array
            (
                "0" => 571228125,
                "1" => 571228125,
                "2" => 571228125,
                "3" => 571228125,
                "4" => 571228125,
                "5" => 571228125,
                "6" => 571228125,
                "7" => 571228125,
                "8" => 571228125,
                "9" => 571228125
            )

);



$unique = array_unique($array["fbid"]);
$diffrence = array_diff_assoc($array["fbid"], $unique) ; // Return the difference 

var_dump($diffrence); 


$unique = array_unique($array["fb_parentid"]); // Get Unique Values 

var_dump($unique);

Output

array
1 => float 1.1563770523754E+14
7 => float 1.1563770523754E+14
array
0 => int 571228125
0
source

All Articles