日期:2014-05-17 浏览次数:20662 次
//比如下面两个数组
$a1=array(2=>array(1,2),3=>array(4));
$a2=array(2=>array(5),5=>array(4));
/**
*我想$a1跟$a2合并的结果为 array(2=>array(1,2,5),3=>array(4),5=>array(4));
**/
$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);