数组的合并
1:数组可以相加,但是键名不能相等,要不然会被抛弃(不是覆盖);
$x = array('a','b'); $y = array(3=>'c',4=>'d'); $z = $x+$y; print_r($z);
浏览器显示结果为:
Array
(
[0] => a
[1] => b
[3] => c
[4] => d
)
2:用array_merge()函数;
1 $x = array('a','b');
2 $y = array(3=>'c',4=>'d');
3
4 $z = array_merge($x,$y);
5 print_r($z);
显示结果和1是一样的:
1 Array 2 ( 3 [0] => a 4 [1] => b 5 [2] => c 6 [3] => d 7 )