note 81546 deleted from function.array-merge by cmb
| From: | cmb@php.net | Date: | Sun, 29 Sep 2019 07:34:29 +0000 |
| Subject: | note 81546 deleted from function.array-merge by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212402@lists.php.net to get a copy of this message | ||
Note Submitter: no_one at nobody dot com
----
PHP is wonderfully decides if an array key could be a number, it is a number! And thus wipes out
the key when you array merge. Just a warning.
$array1['4000'] = 'Grade 1 Widgets';
$array1['4000a'] = 'Grade A Widgets';
$array2['5830'] = 'Grade 1 Thing-a-jigs';
$array2['HW39393'] = 'Some other widget';
var_dump($array1);
var_dump($array2);
//results in...
array(2) {
[4000]=>
string(15) "Grade 1 Widgets"
["4000a"]=>
string(15) "Grade A Widgets"
}
array(2) {
[5830]=>
string(20) "Grade 1 Thing-a-jigs"
["HW39393"]=>
string(17) "Some other widget"
}
var_dump(array_merge($array1,$array2));
//results in...
array(4) {
[0]=>
string(15) "Grade 1 Widgets"
["4000a"]=>
string(15) "Grade A Widgets"
[1]=>
string(20) "Grade 1 Thing-a-jigs"
["HW39393"]=>
string(17) "Some other widget"
}