array_merge_recursive() 与array_merge()函数
程序员文章站
2022-06-02 14:10:35
...
<?php
$a1=array("a"=>"red","b"=>"green");
$a2=array("c"=>"blue","b"=>"yellow");
print_r(array_merge_recursive($a1,$a2));
?>
//打印结果:
Array ( [a] => red [b] => Array ( [0] => green [1] => yellow ) [c] => blue )
array_merge_recursive() 函数把一个或多个数组合并为一个数组,array_merge_recursive() 不会进行键名覆盖,而是将多个相同键名的值递归组成一个数组。
<?php
$a1=array("a"=>"red","b"=>"green");
$a2=array("c"=>"blue","b"=>"yellow");
print_r(array_merge_recursive($a1,$a2));
?>
//打印结果:
Array ( [a] => red [b] => yellow ) [c] => blue )
该函数与array_merge()函数的区别在于处理两个或更多个数组元素有相同的键名时,array_merge()会键名覆盖
上一篇: Java实现FTP上传下载
下一篇: SQL Injection