PHP 4.0 Bug #5970: array_merge() "forgets" some keys in associative arrays
| From: | marc at skirando dot ch | Date: | Fri, 04 Aug 2000 16:10:19 +0000 |
| Subject: | PHP 4.0 Bug #5970: array_merge() "forgets" some keys in associative arrays | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-27718@lists.php.net to get a copy of this message | ||
From: marc@skirando.ch
Operating system: Linux 2.2.14 (RedHat 6.2)
PHP version: 4.0.1pl2
PHP Bug Type: Misbehaving function
Bug description: array_merge() "forgets" some keys in associative arrays
When keys in associative arrays are only composed of integers, the concerned lines of the table are
converted to non-associative lines, after passing through array_merge(). With keys composed of
strings or mixed integers-strings, this misbehaviour doesn't occur.
$array1 = array ("foo" => "bar", "bla" => "blabla");
$array2 = array ("123" => "one two three", "456" => "four
five six");
while (list ($key, $val) = each ($array1)) print "$key : $val \n";
/* this returns :
foo : bar
bla : blabla
it's correct */
while (list ($key, $val) = each ($array2)) print "$key : $val \n";
/* this returns :
123 : one two three
456 : four five six
it's also correct */
$array3 = array_merge ($array1, $array2);
while (list ($key, $val) = each ($array3)) print "$key : $val, ";
/* this returns :
foo : bar
bla : blabla
0 : one two three
1 : four five six
strange, isn't it ? */
Note: I've installed mandrake-cooker rpm's of php4, as the rpms shipped with redhat 6.2
are only old 3.something. Perhaps this can be the cause of the problem ? I haven't tried to
reproduce the bug on another system.