note 96962 deleted from function.array-merge by danbrown
| From: | danbrown@php.net | Date: | Thu, 25 Mar 2010 15:49:56 +0000 |
| Subject: | note 96962 deleted from function.array-merge by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-167399@lists.php.net to get a copy of this message | ||
Note Submitter: contact at covac-software dot com
----
The note by riddlemd (at) gmail {dot} com is NOT entirely correct.
The + on arrays doesn't work like array_merge(). Here are my test cases:
TEST CASE 1
<?php
$a=array('a','b','c');
$b=array('c','d','e');
$c=array_merge($a,$b);
print_r($c);
?>
RESULT 1
Array
(
[0] => a
[1] => b
[2] => c
[3] => c
[4] => d
[5] => e
)
TEST CASE 2
<?php
$a=array('a','b','c');
$b=array('c','d','e');
$c=$a+$b;
print_r($c);
?>
RESULT 2
Array
(
[0] => a
[1] => b
[2] => c
)
As you can see in the second test case, the additional "c", "d" and
"e" aren't used at all.
The plus operator seems to perform an array_merge on integer keys as well.