note 93839 modified in function.array-merge by danbrown
| From: | danbrown@php.net | Date: | Fri, 02 Oct 2009 17:12:08 +0000 |
| Subject: | note 93839 modified in function.array-merge by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-161227@lists.php.net to get a copy of this message | ||
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
)
--was--
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
$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
)
http://php.net/manual/en/function.array-merge.php