欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

PHP array_merge_recursive()函数与示例

发布时间:2023/12/1 50 豆豆
生活随笔 收集整理的这篇文章主要介绍了 PHP array_merge_recursive()函数与示例 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

PHP array_merge_recursive()函数 (PHP array_merge_recursive() function)

array_merge_recursive() function is used to merge two or more arrays, it returns a new array with merged elements. The only difference between array_merge() and array_merge_recursive() function is: "It merges the values having the same key as an array instead of overriding the values."

array_merge_recursive()函数用于合并两个或多个数组,它返回一个具有合并元素的新数组。 “ array_merge()和array_merge_recursive()函数之间的唯一区别是: “它合并与数组具有相同键的值,而不是覆盖这些值。”

Syntax:

句法:

array_merge_recursive(array1, array2,...);

It accepts two or more arrays and returns a new array with merged elements.

它接受两个或多个数组,并返回带有合并元素的新数组。

Examples:

例子:

Input:$arr1 = array("a" => "Hello", "b" => "Hi");$arr2 = array("a" => "Okay!", "d" => "Nothing");Output:Array([a] => Array ([0] => Hello [1] => Okay! )[b] => Hi[d] => Nothing)

PHP code:

PHP代码:

<?php$arr1 = array("a" => "Hello", "b" => "Hi");$arr2 = array("a" => "Okay!", "d" => "Nothing");//merging arrays$arr3 = array_merge_recursive($arr1, $arr2);//printing print_r ($arr3); ?>

Output

输出量

Array ([a] => Array ([0] => Hello [1] => Okay! )[b] => Hi[d] => Nothing )

翻译自: https://www.includehelp.com/php/array_merge_recursive-function-with-example.aspx

总结

以上是生活随笔为你收集整理的PHP array_merge_recursive()函数与示例的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。