如何合并这两个数组? [英] How to merge these two arrays?
本文介绍了如何合并这两个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要合并这两个数组并只获得唯一键值。对此有一个PHP函数? array_merge()不工作。
阵列
(
[1] => 3
[2] => 4
[3] => 1
)排列
(
[1] => 3
[2] => 1
[3] => 2)
结果数组,我想
阵列
(
[1] => 1
[2] => 2
[3] => 3
[4] => 4)
解决方案
$值= array_unique(array_merge($数组1,$数组2));
排序($值);
这将返回在array1和数组2中的唯一值(根据你的例子)。
尝试在这里: HTTP://$c$cpad.org/CeZewRNT
请参阅 array_merge()
和的 array_unique()
。
I want to merge those two arrays and get only the unique key values. Is there a php function for this? array_merge() doesn't work.
Array
(
[1] => 3
[2] => 4
[3] => 1
)
Array
(
[1] => 3
[2] => 1
[3] => 2
)
RESULT ARRAY THAT I WANT
Array
(
[1] => 1
[2] => 2
[3] => 3
[4] => 4
)
解决方案
$values = array_unique(array_merge($array1, $array2));
sort($values);
This returns the unique values from array1 and array2 (as per your example).
Try it here: http://codepad.org/CeZewRNT
See array_merge()
and array_unique()
.
这篇关于如何合并这两个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文