PHP 合并数组,只有 NOT DUPLICATED 值 [英] PHP merge arrays with only NOT DUPLICATED values
本文介绍了PHP 合并数组,只有 NOT DUPLICATED 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将两个数组合并为 1 个数组,但我需要的是在它们共有的主要数据之前删除(我的意思是重复值),合并时我只需要唯一的值.
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.
我该怎么做?
这是数组示例:
第一个数组
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"
}
}
第二个数组
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"
}
}
推荐答案
你可以结合 array_merge()
函数与 array_unique()
函数(两个标题都一目了然)
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 合并数组,只有 NOT DUPLICATED 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文