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

PHP Home Page

Manual Table of Contents
Up to Arrays
Quick Reference
English version of this pageJapanese version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
Arrays
* array
* array_count_values
* array_flip
* 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_unshift
* array_values
* array_walk
* arsort
* asort
* compact
* count
* current
* each
* end
* extract
* in_array
* key
* krsort
* ksort
* list
* next
* pos
* prev
* range
* reset
* rsort
* shuffle
* sizeof
* sort
* uasort
* uksort
* usort
Manual: array_merge
View the source code for this pageSearch the site



Previous page
 array_keys
 Updated
Sat, 12 Aug 2000
array_merge_recursive 
Next page


array_merge

(PHP4 )

array_merge -- Merge two or more arrays

Description

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

array_merge() 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 had the same string keys, then the later value for that key will overwrite previous one. If, however, the arrays have the same numeric key, this does not happen since the values are appended.

Beispiel 1. array_merge() example


$array1 = array("color" => "red", 2, 4);
$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid");
array_merge($array1, $array2);
      

Resulting array will be array("color" => "green", 2, 4, "a", "b", "shape" => "trapezoid").

Anmerkung: This function was added in PHP 4.0.


User Contributed Notes: array_merge


jparker@itchannel.net
11-Jan-2000 07:27
Hmm... perhaps I'm just a bit thick, but isn't there a need for an array_add function.



This could work just like array_merge, but would simply add a new dimension to array where the keys in the n'th array match the keys in the first array.



Then, again perhaps I'm just having one of those days.



JP.



rlynch@ignitionstate.com
27-Jan-2000 01:33
The behavior of the integer-based arrays seems in direct opposition to the ability to be able to have integer-based arrays with holes in them:

<PRE>
$alpha = array(65 => 'A', 66 => 'B', 67 => 'C');
$assoc = array(65 => 'Retire', 66 => 'Route');
$merge = array_merge($alpha, $assoc);
</PRE>
This wipes out the association I had going and re-indexes from 0 :-(



Maybe I'm just goofy, but this seems against the flavor of PHP to me.

At any rate, it's something folks should know.



david@audiogalaxy.com
04-Mar-2000 02:03
See my posts about array_reverse. Key values are actually always 'associative' - i.e. there's not some different flavor of array when you start to use strings instead of numbers or start to use numbers out of order. So, how exactly would you like functions like array_merge to distinguish the situations where you want to keep the associations from the (probably much more prevalent) situations where people just want to concatenate two arrays. Most people aren't thinking "$B[0] should replace $A[0], $B[1] should replace $A[1], ... ". I think the distinction it does make - merge if the keys are strings, concatenate if the keys are numbers - is fair. Maybe there should really be separate functions for these two processes.


 About Notes


Previous page
 array_keys
 Updated
Sat, 12 Aug 2000
array_merge_recursive 
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.