note 96962 added to function.array-merge
| From: | contact at covac-software dot com | Date: | Thu, 25 Mar 2010 08:41:37 +0000 |
| Subject: | note 96962 added to function.array-merge | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-167376@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 69.147.83.197
Probable Submitter: 195.158.104.176
----
Manual Page -- http://www.php.net/manual/en/function.array-merge.php
Edit -- https://master.php.net/note/edit/96962
Del: integrated -- https://master.php.net/note/delete/96962/integrated
Del: useless -- https://master.php.net/note/delete/96962/useless
Del: bad code -- https://master.php.net/note/delete/96962/bad+code
Del: spam -- https://master.php.net/note/delete/96962/spam
Del: non-english -- https://master.php.net/note/delete/96962/non-english
Del: in docs -- https://master.php.net/note/delete/96962/in+docs
Del: other reasons-- https://master.php.net/note/delete/96962
Reject -- https://master.php.net/note/reject/96962
Search -- https://master.php.net/manage/user-notes.php