PHP数组合并只用不重复的值 [英] PHP merge arrays with only NOT DUPLICATED values
本文介绍了PHP数组合并只用不重复的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要两个数组合并为1阵列,但我需要的是主数据之前删除他们b超视距有共同的(重复的值,我的意思),合并时,我只需要唯一的值。
我怎么能做到这一点?
这是数组例如:
第一阵列
阵列(3){[0] =>对象(stdClass的)第17(1){[电子邮件] =>串(7)gffggfg} [1] =>对象(stdClass的)第18(1){[电子邮件] =>串(6)wefwef@test.it} [2] =>对象(stdClass的)第19(1){[电子邮件] =>串(6)wefewf}}
第二阵列
阵列(3){[0] =>对象(stdClass的)第17(1){[电子邮件] =>串(7)gffggfg@test.it} [1] =>对象(stdClass的)第18(1){[电子邮件] =>串(6)wefwef} [2] =>对象(stdClass的)第19(1){[电子邮件] =>串(6)wefewf}}
解决方案
您可以用array_unique()函数结合array_merge()函数(包括标题是pretty不言自明)
$阵列= array_unique(array_merge($数组1,$数组2));
i need to merge two arrays into 1 array but what i need is to remove before the main data they b oth have in common (duplicated values i mean), i need only unique values when merged.
how can i do that?
this is the array example:
first array
array(3) { [0]=> object(stdClass)#17 (1) { ["email"]=> string(7) "gffggfg" } [1]=> object(stdClass)#18 (1) { ["email"]=> string(6) "wefwef@test.it" } [2]=> object(stdClass)#19 (1) { ["email"]=> string(6) "wefewf" } }
second array
array(3) { [0]=> object(stdClass)#17 (1) { ["email"]=> string(7) "gffggfg@test.it" } [1]=> object(stdClass)#18 (1) { ["email"]=> string(6) "wefwef" } [2]=> object(stdClass)#19 (1) { ["email"]=> string(6) "wefewf" } }
解决方案
You can combine the array_merge() function with the array_unique() function (both titles are pretty self-explanatory)
$array = array_unique (array_merge ($array1, $array2));
这篇关于PHP数组合并只用不重复的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文