note 75268 deleted from function.array-merge by salathe
| From: | salathe@php.net | Date: | Mon, 06 Sep 2021 22:43:32 +0000 |
| Subject: | note 75268 deleted from function.array-merge by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-216878@lists.php.net to get a copy of this message | ||
Note Submitter: RQuadling at GMail dot com
----
For asteddy at tin dot it and others who are trying to merge arrays and keep the keys, don't
forget the simple + operator.
Using the array_merge_keys() function (with a small mod to deal with multiple arguments), provides
no difference in output as compared to +.
<?php
$a = array(-1 => 'minus 1');
$b = array(0 => 'nought');
$c = array(0 => 'nought');
var_export(array_merge_keys($a,$b));
var_export($a + $b);
var_export(array_merge_keys($a,$b,$c));
var_export($a + $b + $c);
?>
results in ...
array ( -1 => 'minus 1', 0 => 'nought',)
array ( -1 => 'minus 1', 0 => 'nought',)
array ( -1 => 'minus 1', 0 => 'nought',)
array ( -1 => 'minus 1', 0 => 'nought',)