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 Haskell School of Expression

The Haskell School of Expression

Paul Hudak / Cambridge University Press / 2000-01 / USD 95.00

Functional programming is a style of programming that emphasizes the use of functions (in contrast to object-oriented programming, which emphasizes the use of objects). It has become popular in recen......一起来看看 《The Haskell School of Expression》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

SHA 加密
SHA 加密

SHA 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器