时间:2021-07-01 10:21:17 帮助过:25人阅读
结果为 array(2=>array(1,2,5),3=>array(4),5=>array(4));
//比如下面两个数组
$a1=array(2=>array(1,2),3=>array(4));
$a2=array(2=>array(5),5=>array(4));
/**
*我想$a1跟$a2合并的
$keys = array_unique(array_keys(array_merge($arr1, $arr2)));
foreach($keys as $k) {
.....
}
$a1 = array(2=>array(1,2),3=>array(4));Array
$a2 = array(2=>array(5),5=>array(4));
foreach($a2 as $k=>$v) {
if(isset($a1[$k])) $a1[$k] = array_merge($a1[$k], $v);
else $a1[$k] = $v;
}
print_r($a1);