note 22157 added to function.array-merge
| From: | carlos@php.net | Date: | Sat, 08 Jun 2002 13:47:48 +0000 |
| Subject: | note 22157 added to function.array-merge | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-31601@lists.php.net to get a copy of this message | ||
If you merges two (or more arrays, i.e. $a1, $a2) with keys that exists in both arrays and you want
in result the array with only new (non existing in $a1) keys integrated and rest of $a1 untouched,
put the array you want to save as the latter argument.
I.e. to asimilate $a2 by $a1:
$a1 = array("a"=>10, "b"=>20);
$a2 = array("a"=>0, "c"=>30);
do:
array_merge( $a2, $a1 ));
otherwise value with key "a" will be replaced with that one from $a2 and we don't
want this. If you have more arrays, the order of array_merge() argumens in case of such merge should
(in general) be descending from less to most 'importatant'.
--
http://www.php.net/manual/en/function.array-merge.php
http://master.php.net/manage/user-notes.php?action=edit+22157
http://master.php.net/manage/user-notes.php?action=delete+22157
http://master.php.net/manage/user-notes.php?action=reject+22157