问题是把下面两个二维数组合并,根据他们相同的ID合并成一个数组
$arr = array( array('id'=>1,'name'=>'zhangsan','sex'=>'n'), array('id'=>2,'name'=>'lisi','sex'=>'v'), array('id'=>3,'name'=>'wangwu','sex'=>'n'), array('id'=>4,'name'=>'zhaoliu','sex'=>'v'), array('id'=>5,'name'=>'xiaoqi','sex'=>'n'));$arr1 = array( array('id'=>3,'age'=>'20'), array('id'=>5,'age'=>'21'), array('id'=>6,'age'=>'30'));
$arr = array( array('id'=>3,'name'=>'wangwu','sex'=>'n','age'=>'20'), array('id'=>5,'name'=>'xiaoqi','sex'=>'n','age'=>'21'));
好吧自己弄好了
$bbs = array(); foreach ($arr as $k => $v) { foreach ($arr1 as $key => $value) { if($value['id']==$v['id']){ $bbs[] = array_merge($arr[$k],$arr1[$key]); } } }
array_merge_recursive
foreach ( $arr as $v ) {
$tmp[$v['id']] = $v;
}
foreach ( $arr1 as $v ) {
$tmp[$v['id']] = $v;
}
print_r($tmp);