数组的合并: array_merge() 两个数组的元素会合并成一个数组的元素
数组的合并:
例:
$a = array(
'where' => 'uid=1',
'order' => 'uid',
);
$b = array(
'where' => 'uid=2',
'order' => 'uid desc',
);
$c = array_merge($a,$b);
print_r($c);
输出结果为:
Array ( [where] => uid=2 [order] => uid desc )
如果两个数组存在相同的key,则后面那个会覆盖前面的
$c=array_merge($b,$a);
输出结果为:
Array ( [where] => uid=1 [order] => uid )
$c = $a + $b;
print_r($c);
输出结果为:
Array ( [where] => uid=1 [order] => uid )
+操作符,如果两个数组存在相同的key,则前面那个会覆盖后面的
$c = $b + $a;
print_t($c);
输出结果为:
Array ( [where] => uid=2 [order] => uid desc )
如果是数组索引:
$a = array(
1 => 'uid=1',
2 => 'uid',
);
$b = array(
1 => 'uid=2',
3 => 'uid desc',
);
$c = array_merge($a,$b);
print_r($c);
输出结果为:
Array ( [0] => uid=1 [1] => uid [2] => uid=2 [3] => uid desc )
类似于foreach每个数组元素,然后将其压入新的堆栈中
$c = array_merge($b,$a);
print_r($c);
输出结果为:
Array ( [0] => uid=2 [1] => uid desc [2] => uid=1 [3] => uid
$c = $a + $b;
print_r($c);
输出结果为:
Array ( [1] => uid=1 [2] => uid [3] => uid desc )
+类似于foreach,但是遇到相同的key,则不再处理
$c = $b + $a;
print_r($c);
输出结果为:
Array ( [1] => uid=2 [3] => uid desc [2] => uid )