|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-03-02 18:21 UTC] forjest at gmail dot com
Description:
------------
array_merge interprets string keys, containing only digits as numeric keys, if numeric overflow not reached.
String keys should works as strings regarless of their contents.
Test script:
---------------
var_dump(array_merge(array('t777'=> array("I'm a string"))));
var_dump(array_merge(array("42424242"=> array("I'm a string of digits"))));
var_dump(array_merge(array("777777777777777777777777777777777777777777777777777777777"=> array("I'm string of digits too"))));
var_dump(is_string("42424242"));
var_dump(is_string(42424242));
var_dump(is_string("777777777777777777777777777777777777777777777777777777777"));
Expected result:
----------------
array(1) {
["t777"]=>
array(1) {
[0]=>
string(12) "I'm a string"
}
}
array(1) {
["42424242"]=>
array(1) {
[0]=>
string(22) "I'm a string of digits"
}
}
array(1) {
["777777777777777777777777777777777777777777777777777777777"]=>
array(1) {
[0]=>
string(24) "I'm string of digits too"
}
}
bool(true)
bool(false)
bool(true)
Actual result:
--------------
array(1) {
["t777"]=>
array(1) {
[0]=>
string(12) "I'm a string"
}
}
array(1) {
[0]=>
array(1) {
[0]=>
string(22) "I'm a string of digits"
}
}
array(1) {
["777777777777777777777777777777777777777777777777777777777"]=>
array(1) {
[0]=>
string(24) "I'm string of digits too"
}
}
bool(true)
bool(false)
bool(true)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 07:00:01 2025 UTC |
Maybe, simpler example. OK: $c = array('01'=>3, '03'=>10); $d = array('05'=>44, '07'=>3); var_dump(array_merge($c,$d)); Failed: $a = array('01'=>1, '02'=>73); $b = array('10'=>11, '11'=>23); var_dump(array_merge($a,$b));This is not particularly related to array_merge(), but to the handling of array keys in general. From the manual[1]: | Strings containing valid integers will be cast to the integer | type. So var_dump(array('10'=>11, '11'=>23)); outputs: array(2) { [10] => int(11) [11] => int(23) } and not: array(2) { '10' => int(11) '11' => int(23) } The rest is documented on the array_merge() man page: | Values in the input array with numeric keys will be renumbered | with incrementing keys starting from zero in the result array. [1] <http://php.net/manual/en/language.types.array.php>