note 75527 deleted from function.array-merge by salathe
| From: | salathe@php.net | Date: | Mon, 06 Sep 2021 22:44:12 +0000 |
| Subject: | note 75527 deleted from function.array-merge by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-216885@lists.php.net to get a copy of this message | ||
Note Submitter: Joe at neosource dot com dot au
----
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.