array_merge & array_unique

后端 未结 5 737
-上瘾入骨i
-上瘾入骨i 2020-12-11 02:46

Is there an array function in PHP that somehow does array_merge, comparing the values, ignoring the keys? I think that array_unique(array_merge($a, $b

5条回答
  •  一个人的身影
    2020-12-11 03:08

    array_merge will ignore numeric keys, so in your example array_merge($a, $b) would give you $ab, there is no need to call array_unique().

    if you have string keys (i.e. an associative array) use array_values() first:

    array_merge(array_values($a), array_values($b));
    

提交回复
热议问题