note 106861 deleted from function.array-merge by danbrown
| From: | danbrown@php.net | Date: | Tue, 03 Jan 2012 22:14:37 +0000 |
| Subject: | note 106861 deleted from function.array-merge by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-185340@lists.php.net to get a copy of this message | ||
Note Submitter: David at ElanElan dot com
----
A simpler way to achieve the "merge arrays WITHOUT REINDEXING numerical keys and WITH
OVERWRITING" of the ventzy dot public at gmail dot com post of 07-Dec-2011 is:
$result = $array2 + $array1;
which gives the same result as
$result = array_diff_key($array1, $array2) + $array2;
albeit with the keys in a different order, as explained in the post of w_barath at hotmail dot com
04-Oct-2011 below.
The point to note is that the array to do the overwriting must be the one on the left of the +
operator.