note 75527 added to function.array-merge
| From: | Joeatneosourcedotcomdotau at osu1 dot php dot net | Date: | Mon, 04 Jun 2007 06:51:18 +0000 |
| Subject: | note 75527 added to function.array-merge | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-127177@lists.php.net to get a copy of this message | ||
I found the "simple" method of adding arrays behaves differently as described in the
documentation in PHP v5.2.0-10.
$array1 + $array2 will only combine entries for keys that don't already exist.
Take the following example:
$ar1 = array('a', 'b');
$ar2 = array('c', 'd');
$ar3 = ($ar1 + $ar2);
print_r($ar3);
Result:
Array
(
[0] => a
[1] => b
)
Where as:
$ar1 = array('a', 'b');
$ar2 = array('c', 'd');
$ar3 = array_merge($ar1, $ar2);
print_r($ar3);
Result:
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
)
Hope this helps someone.
----
Server IP: 203.16.234.20
Probable Submitter: 211.28.240.82
----
Manual Page -- http://www.php.net/manual/en/function.array-merge.php
Edit -- https://master.php.net/note/edit/75527
Del: integrated -- https://master.php.net/note/delete/75527/integrated
Del: useless -- https://master.php.net/note/delete/75527/useless
Del: bad code -- https://master.php.net/note/delete/75527/bad+code
Del: spam -- https://master.php.net/note/delete/75527/spam
Del: non-english -- https://master.php.net/note/delete/75527/non-english
Del: in docs -- https://master.php.net/note/delete/75527/in+docs
Del: other reasons-- https://master.php.net/note/delete/75527
Reject -- https://master.php.net/note/reject/75527
Search -- https://master.php.net/manage/user-notes.php