PHP array_diff输出 - 不清楚

时间:2013-01-16 23:41:29

标签: php arrays

这是阵列。

Array1
(
[439] => dsaffsdfdfdfsffdsf
[379] => 3454
[375] => 3 ///why is it removed in the resulting array?
[436] => Fdsafdfsdf
[432] => 3  /// this one too
[431] => 2
[385] => 499
[434] => 3501
[435] => 2013-01-16
[430] => 1
[440] => fsdzsdaffdsfffdsf
[406] => YES
[438] => 32442344324324234
[376] => 3
)

Array2
(
[376] => 3
[385] => 499
)

array_diff(array1, array2)

result
(
[439] => dsaffsdfdfdfsffdsf
[379] => 3454
[436] => Fdsafdfsdf
[431] => 2
[434] => 3501
[435] => 2013-01-16
[430] => 1
[440] => fsdzsdaffdsfffdsf
[406] => YES
[438] => 32442344324324234
)

对我来说很奇怪。任何的想法?它的删除基于价值?

我只想从Array2

中删除Array1个元素

1 个答案:

答案 0 :(得分:0)

手册是您最好的朋友:

  • array_diff()将array1与array2进行比较并返回差异。
  • array_diff_assoc()将array1与array2进行比较并返回差异。与array_diff()不同,数组键也用于比较。
  • array_diff_key()将array1中的键与来自array2的键进行比较,并返回差值。此函数类似于array_diff(),除了对键而不是值进行比较。