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()函数与示例的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 颐和园发朋友圈的句子
- 下一篇: php globals_PHP $ GL