3

我有一个数组

    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
            )

)

这里 0 、 1 和 7 重复。首先,我想获取重复索引(0,1,7)。其次,我想显示一对一的索引。在上面的例子中只有第 0 个。

之后我想从 [fb_parentid] 和 [fbid] 中删除 1 和 7

你能帮助我吗 ?

4

2 回答 2

6

您正在寻找array_unique函数。

$new_array = array_unique($old_array);
于 2012-04-24T17:41:41.667 回答
0

尝试

$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);

输出

array
1 => float 1.1563770523754E+14
7 => float 1.1563770523754E+14
array
0 => int 571228125
于 2012-04-24T17:49:30.697 回答