1 $arr1 = array(1, 2, 3, 4, 'color'=>'red'); 2 $arr2 = array('a', 'b', 'c', 'color'=>'blue'); 3 print_r(array_merge($arr1, $arr2));//同名索引的值会覆盖 4 print_r(array_merge_recursive($arr1, $arr2));//相同的键名 不会覆盖,如果是单个元素会在转为一个一维数组
Both functions are used to merge arrays. Parameters can be arrays of 1 to n.(Uh, I don’t understand what is used when the parameter is an array. Who knows? Tell me.)
Output result:
Line 3:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[color] => blue//Please note the difference in this line
[4] => a
[5] => b
[6] => c
)
Line 4:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[color] => Array//Pay attention to the difference here
(
[0] => red
[1] => blue
)
[4] => a
[5] => b
[6] => c
)