★ wanayoo — archive 1999 http://php.net/manual/it/function.array-merge-recursive.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Arrays
Quick Reference
Arrays
English version of this pageGerman version of this pageJapanese version of this page
Italian version of this pageFrench version of this pageHungarian version of this page
Dutch version of this page
* array
* array_count_values
* array_diff
* array_flip
* array_intersect
* array_keys
* array_merge
* array_merge_recursive
* array_multisort
* array_pad
* array_pop
* array_push
* array_rand
* array_reverse
* array_shift
* array_slice
* array_splice
* array_unique
* array_unshift
* array_values
* array_walk
* arsort
* asort
* compact
* count
* current
* each
* end
* extract
* in_array
* key
* krsort
* ksort
* list
* natsort
* natcasesort
* next
* pos
* prev
* range
* reset
* rsort
* shuffle
* sizeof
* sort
* uasort
* uksort
* usort

  Thanks to:
 Chek.com
 easyDNS
 VA Linux Systems

  Related sites:
Apache
MySQL
PostgreSQL
Zend Tech.

  Community:
LinuxFund.org
OSDN
Manual: array_merge_recursive
View the source code for this pageSearch the site



Previous page
 array_merge
 Updated
Fri, 03 Nov 2000
array_multisort 
Next page


array_merge_recursive

(PHP 4 >= 4.0.1)

array_merge_recursive -- Merge two or more arrays recursively

Description

array array_merge_recursive (array array1, array array2 [, array ...])

Array_merge_recursive() merges the elements of two or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array.

If the input arrays have the same string keys, then the values for these keys are merged together into an array, and this is done recursively, so that if one of the values is an array itself, the function will merge it with a corresponding entry in another array too. If, however, the arrays have the same numeric key, the later value will not overwrite the original value, but will be appended.

Esempio 1. Array_merge_recursive() example


$ar1 = array ("color" => array ("favorite" => "red"), 5);
$ar2 = array (10, "color" => array ("favorite" => "green", "blue"));
$result = array_merge_recursive ($ar1, $ar2);
      

Resulting array will be array ("color" => array ("favorite" => array ("red", "green"), "blue"), 5, 10).

See also array_merge().


User Contributed Notes: array_merge_recursive


kc@hireability.com
12-Oct-2000 05:08
There seemed to be no built in function that would merge two arrays recursively and clobber any existing key/value pairs. Array_Merge() is not recursive, and array_merge_recursive seemed to give unsatisfactory results... it would append duplicate key/values.

So here's a cross between array_merge and array_merge_recursive
---------------------------------
function array_merge_clobber($a1,$a2) {
if(!is_array($a1) || !is_array($a2)) return false;
$newarray = $a1;
while (list($key, $val) = each($a2)) {
if (is_array($val) && is_array($newarray[$key])) {
$newarray[$key] = array_merge_clobber($newarray[$key], $val);
} else {
$newarray[$key] = $val;
}
}
return $newarray;
}
-------------------------------------



 About Notes


Previous page
 array_merge
 Updated
Fri, 03 Nov 2000
array_multisort 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.