Doc #52852 [Asn->Csd]: array_merge modifies numerical keys even if non-numerical

From: Date: Wed, 15 Sep 2010 10:29:54 +0000
Subject: Doc #52852 [Asn->Csd]: array_merge modifies numerical keys even if non-numerical
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-5051@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: Assigned +Status: Closed Type: Documentation Problem Package: Documentation problem Operating System: osx PHP Version: 5.3.3 Assigned To: aharvey Block user comment: N New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. Previous Comments: ------------------------------------------------------------------------ [2010-09-15 12:29:45] aharvey@php.net Automatic comment from SVN on behalf of aharvey Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=303390 Log: Fix doc bug #52852 (array_merge modifies numerical keys even if non-numerical). ------------------------------------------------------------------------ [2010-09-15 12:20:56] aharvey@php.net Definitely a documentation issue; in fact, there's an example on the same manual page that shows the same behaviour as your test script! ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#5051) next »