note 115209 deleted from function.array-merge by salathe
| From: | salathe@php.net | Date: | Mon, 06 Sep 2021 22:48:29 +0000 |
| Subject: | note 115209 deleted from function.array-merge by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-216920@lists.php.net to get a copy of this message | ||
Note Submitter: Angel I
----
An addition to what Julian Egelstaff above wrote - the array union operation (+) is not doing an
array_unique - it will just not use the keys that are already defined in the left array. The
difference between union and merge can be seen in an example like this:
<?php
$arr1['one'] = 'one';
$arr1['two'] = 'two';
$arr2['zero'] = 'zero';
$arr2['one'] = 'three';
$arr2['two'] = 'four';
$arr3 = $arr1 + $arr2;
var_export( $arr3 );
# array ( 'one' => 'one', 'two' => 'two',
'zero' => 'zero', )
$arr4 = array_merge( $arr1, $arr2 );
var_export( $arr4 );
# array ( 'one' => 'three', 'two' => 'four',
'zero' => 'zero', )
?>