note 96844 modified in function.array-merge by danbrown
| From: | danbrown@php.net | Date: | Fri, 19 Mar 2010 15:29:31 +0000 |
| Subject: | note 96844 modified in function.array-merge by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-167208@lists.php.net to get a copy of this message | ||
be aware there is a slight difference:
<?php
$array1 = array('lang'=>'js','method'=>'GET');
$array2 =
array('lang'=>'php','browser'=>'opera','method'=>'POST');
?>
BETWEEN:
<?php array_merge($array2,$array1); ?>
outputs: Array ( [lang] => js [browser] => opera [method] => GET )
notice that the repeated keys will be overwritten by the ones of $array1, maintaining those, because
it is the array that is being merged
AND
<?php array_merge($array1,$array2); ?>
outputs: Array ( [lang] => php [method] => POST [browser] => opera )
here the oposite takes place: array1 will have its elements replaced by those of array2.
--was--
be aware there is a slight difference:
$array1 = array('lang'=>'js','method'=>'GET');
$array2 =
array('lang'=>'php','browser'=>'opera','method'=>'POST');
BETWEEN:
array_merge($array2,$array1);
outputs: Array ( [lang] => js [browser] => opera [method] => GET )
notice that the repeated keys will be overwritten by the ones of $array1, maintaining those, because
it is the array that is being merged
AND
array_merge($array1,$array2);
outputs: Array ( [lang] => php [method] => POST [browser] => opera )
here the oposite takes place: array1 will have its elements replaced by those of array2.
http://php.net/manual/en/function.array-merge.php