我有两个数组,我想合并它们而不复制“name”,
$array1[]= array(name['udi','ari'],id['1','2'])
$array2[]= array(name['udi','ari'],age['22','18'])
结果
$arrayresult[]= array(name['udi','ari'],id['1','2'],age['22','18'])
答案 0 :(得分:0)
我认为您正在寻找的是array_merge: http://php.net/manual/en/function.array-merge.php
$arrayresult = array_merge($array1,$array2);
应该给你:
$arrayresult = array(name('udi','ari'),id('1','2'),age('22','18'))
答案 1 :(得分:0)
只需使用array_merge将两个数组合并为:
示例:强>
<?php
$array1 = array(
'name'=>array('udi','ari'),
'id'=>array('1','2'),
);
$array2 = array(
'name'=>array('udi','ari'),
'age'=>array('22','18'),
);
$newArr = array_merge($array1,$array2);
echo "<pre>";
print_r($newArr);
?>
<强>结果:强>
Array
(
[name] => Array
(
[0] => udi
[1] => ari
)
[id] => Array
(
[0] => 1
[1] => 2
)
[age] => Array
(
[0] => 22
[1] => 18
)
)
答案 2 :(得分:0)
您可以先使用$result=array_merge($array1,$array2)
,然后使用$result=array_unique($result)
删除重复值。