Home > php教程 > php手册 > body text

php-Arrays函数-array_merge_recursive-递归地合并一个或多个数组

WBOY
Release: 2016-06-13 10:49:26
Original
1137 people have browsed it

array_merge_recursive() 递归地合并一个或多个数组

【功能】
         该函数将一个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面。
         返回作为结果的数组。如果输入的数组中有相同的字符串键名,则这些值会被合并到一个
         数组中,这将递归下去,因此如果一个值本身是一个数组,则该函数将按照相应的条目把它合并
         为另一个数组。然而,如果数组具体相同的数组键名,后一个值将不会覆盖原来的值,而
         是附加到后面。
【使用范围】
         php4>4.0.1、php5.
【使用】
         array array_merge_recursive( array array1[,array...]  )
         arrayn/必需/即将用来合并的数组
【示例】
[php]
$arr1 = array("color"=>array("favorite"=>"red"),5); 
$arr2 = array(10,"color"=>array("favorite"=>"green","blue")); 
var_dump(array_merge_recursive($arr1,$arr2)); 
/*
array(3) {
  ["color"]=>
  array(2) {
    ["favorite"]=>
    array(2) {
      [0]=>
      string(3) "red"
      [1]=>
      string(5) "green"
    }
    [0]=>
    string(4) "blue"
  }
  [0]=>
  int(5)
  [1]=>
  int(10)
}
*/ 

 


摘自 zuodefeng的笔记

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!