Bug->Doc #52852 [Opn->Asn]: array_merge modifies numerical keys even if non-numerical
| From: | aharvey@php.net | Date: | Wed, 15 Sep 2010 10:20:56 +0000 |
| Subject: | Bug->Doc #52852 [Opn->Asn]: array_merge modifies numerical keys even if non-numerical | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-5050@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52852&edit=1
ID: 52852
Updated by: aharvey@php.net
Reported by: fh-phpbug2 at fholzhauer dot de
Summary: array_merge modifies numerical keys even if
non-numerical
-Status: Open
+Status: Assigned
-Type: Bug
+Type: Documentation Problem
Package: Documentation problem
Operating System: osx
PHP Version: 5.3.3
-Assigned To:
+Assigned To: aharvey
Block user comment: N
New Comment:
Definitely a documentation issue; in fact, there's an example on the
same manual page that shows the same behaviour as your test script!
Previous Comments:
------------------------------------------------------------------------
[2010-09-15 12:15:41] fh-phpbug2 at fholzhauer dot de
Description:
------------
Not sure if this a documentation problem or a function problem, but
either way, it is a bug :-)
The documentation for array_merge says "If all of the arrays contain
only numeric keys, the resulting array is given incrementing keys
starting from zero."
However, integer keys are always renumbered even if there is a
non-numeric key present.
Test script:
---------------
<?php
$test = array('foo' => false, 1=>2.34, 2=>13.12);
var_dump($test);
$result = array_merge(array(),$test);
var_dump($result);
Expected result:
----------------
array(3) {
["foo"]=>
bool(false)
[1]=>
float(2.34)
[2]=>
float(13.12)
}
array(3) {
["foo"]=>
bool(false)
[1]=>
float(2.34)
[2]=>
float(13.12)
}
Actual result:
--------------
array(3) {
["foo"]=>
bool(false)
[1]=>
float(2.34)
[2]=>
float(13.12)
}
array(3) {
["foo"]=>
bool(false)
[0]=>
float(2.34)
[1]=>
float(13.12)
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52852&edit=1