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

PHP Home Page

Manual Table of Contents
Up to Tableaux
Quick Reference
English version of this pageGerman version of this pageJapanese version of this pageItalian version of this pageHungarian version of this page
Tableaux
* array
* array_count_values
* array_flip
* array_keys
* array_merge
* array_pad
* array_pop
* array_push
* 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
Sun, 06 Aug 2000
array_pad 
Next page


array_merge

(PHP4 )

array_merge -- Rassemble plusieurs tableaux

Description

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

array_merge() rassemble les éléments de plusieurs tableaux ensemble, en ajoutant les valeurs de l'un à la fin de l'autre. Le résultat est un tableau.

Si les tableaux ont des clés en commun, la dernière valeur rencontrée écrasera l'ancienne. Pour les valeurs numériques, cela n'arrive pas, car alors, les valeurs sont ajoutées en fin de tableau.

Exemple 1. Exemple avec array_merge()


$array1 = array ("couleur" => "rouge", 2, 4);
$array2 = array ("a", "b", "couleur" => "vert", "forme" => "trapézoïde");
array_merge ($array1, $array2);
      

Le résultat sera array("couleur" => "vert", 2, 4, "a", "b", "forme" => "trapézoïde").

Note: Cette fonction a été ajoutée dans 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
Sun, 06 Aug 2000
array_pad 
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.