note 93839 deleted from function.array-merge by cmb
| From: | cmb@php.net | Date: | Sun, 29 Sep 2019 07:35:40 +0000 |
| Subject: | note 93839 deleted from function.array-merge by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212404@lists.php.net to get a copy of this message | ||
Note Submitter: allankelly
----
More on the union (+) operator:
the order of arrays is important and does not agree in my test below
with the other posts. The 'unique' operation preserves the initial key-value and discards
later duplicates.
PHP 5.2.6-2ubuntu4.2
<?php
$a1=array('12345'=>'a', '23456'=>'b',
'34567'=>'c', '45678'=>'d');
$a2=array('34567'=>'X');
$a3=$a1 + $a2;
$a4=$a2 + $a1;
print('a1:'); print_r($a1);
print('a2:'); print_r($a2);
print('a3:'); print_r($a3);
print('a4:'); print_r($a4);
?>
a1:Array
(
[12345] => a
[23456] => b
[34567] => c
[45678] => d
)
a2:Array
(
[34567] => X
)
a3:Array
(
[12345] => a
[23456] => b
[34567] => c
[45678] => d
)
a4:Array
(
[34567] => X
[12345] => a
[23456] => b
[45678] => d
)