PHP array_merge_recursive() 函数

PHP 教程 · 2019-01-22 10:43:12

实例

把两个数组合并为一个数组:

<?php
$a1=array("a"=>"red","b"=>"green");
$a2=array("c"=>"blue","b"=>"yellow");
print_r(array_merge_recursive($a1,$a2));
?>

定义和用法

array_merge_recursive() 函数用于把一个或多个数组合并为一个数组。

该函数与 array_merge() 函数之间的不同是在处理两个或更多个数组元素有相同的键名的情况。array_merge_recursive() 不会进行键名覆盖,而是将多个相同键名的值递归组成一个数组。

注释:如果您仅仅向 array_merge_recursive() 函数输入一个数组,结果与 array_merge() 相同,函数将返回带有整数键名的新数组,其键名以 0 开始进行重新索引。

语法


array_merge_recursive(array1,array2,array3...)


参数 描述
array1 必需。规定数组。
array2 可选。规定数组。
array3 可选。规定数组。

技术细节

返回值: 返回合并的数组。
PHP 版本: 4.0.1+

点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

The Art of Computer Programming, Volumes 1-3 Boxed Set

The Art of Computer Programming, Volumes 1-3 Boxed Set

Donald E. Knuth / Addison-Wesley Professional / 1998-10-15 / USD 199.99

This multivolume work is widely recognized as the definitive description of classical computer science. The first three volumes have for decades been an invaluable resource in programming theory and p......一起来看看 《The Art of Computer Programming, Volumes 1-3 Boxed Set》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具