如何比较数组的差异?

时间:2013-10-02 15:54:56

标签: php arrays compare

如何在这里和第三个数组中找到两个数组类型的区别,这就产生了不同。

第一个数组

Array ( 
    [0] => Array ( [DATE_PIC] => 1380095187 [LINK_PIC] => http://distilleryimage1.s3.amazonaws.com/95567b0025b611e3828a22000a9f191e_5.jpg [TAG_PIC] => pricelessmoscow )
    [1] => Array ( [DATE_PIC] => 1380077949 [LINK_PIC] => http://distilleryimage6.s3.amazonaws.com/72d65c62258e11e3af2822000ab6843e_5.jpg [TAG_PIC] => pricelessmoscow ) 
    [2] => Array ( [DATE_PIC] => 1380064601 [LINK_PIC] => http://distilleryimage5.s3.amazonaws.com/5ea5e06a256f11e3b8e322000a1f97ed_5.jpg [TAG_PIC] => pricelessmoscow ) 
    [3] => Array ( [DATE_PIC] => 1380042830 [LINK_PIC] => http://distilleryimage2.s3.amazonaws.com/ae50a416253c11e3a7361231392838b2_5.jpg [TAG_PIC] => pricelessmoscow ) 
    [4] => Array ( [DATE_PIC] => 1380059102 [LINK_PIC] => http://distilleryimage3.s3.amazonaws.com/90f54f90256211e38be922000aeb0c6a_5.jpg [TAG_PIC] => pricelessmoscow ) 
    [5] => Array ( [DATE_PIC] => 1380052285 [LINK_PIC] => http://distilleryimage2.s3.amazonaws.com/b207ee00255211e3ade722000a1faea4_5.jpg [TAG_PIC] => pricelessmoscow ) 
)

第二个数组

Array ( 
    [13] => Array ( [DATE_PIC] => 1364235512 [LINK_PIC] => http://distilleryimage11.s3.amazonaws.com/6697e58e957811e28d1322000a1fb079_5.jpg [TAG_PIC] => pricelessmoscow ) 
    [14] => Array ( [DATE_PIC] => 1369210746 [LINK_PIC] => http://distilleryimage2.s3.amazonaws.com/44f9503ac2b811e2884a22000a9f1588_5.jpg [TAG_PIC] => pricelessmoscow ) 
    [15] => Array ( [DATE_PIC] => 1370497637 [LINK_PIC] => http://distilleryimage11.s3.amazonaws.com/8bcf5a94ce6c11e28e8222000aa82017_5.jpg [TAG_PIC] => pricelessmoscow ) 
    [16] => Array ( [DATE_PIC] => 1380014431 [LINK_PIC] => http://distilleryimage2.s3.amazonaws.com/8f1ad9aa24fa11e382b422000a1f9ab7_5.jpg [TAG_PIC] => pricelessmoscow ) 
    [17] => Array ( [DATE_PIC] => 1377693693 [LINK_PIC] => http://distilleryimage2.s3.amazonaws.com/2b7983680fdf11e38c8722000a1faff5_5.jpg [TAG_PIC] => pricelessmoscow ) 
    [18] => Array ( [DATE_PIC] => 1370708530 [LINK_PIC] => http://distilleryimage3.s3.amazonaws.com/91e27672d05711e2867a22000a9f1266_5.jpg [TAG_PIC] => pricelessmoscow ) 
    [19] => Array ( [DATE_PIC] => 1370013677 [LINK_PIC] => http://distilleryimage3.s3.amazonaws.com/bd348016ca0511e2939b22000a1f9251_5.jpg [TAG_PIC] => pricelessmoscow ) 
)

array_diff 函数返回:

  

Array()

虽然很明显阵列的内容不同。

1 个答案:

答案 0 :(得分:1)

尝试serialize()array_unique()unserialize() merged数组:

$buffer = array_map('serialize', array_merge($array1, $array2));
$result = array_map('unserialize', array_unique($buffer));

Test@3v4l