php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #52852 array_merge modifies numerical keys even if non-numerical
Submitted: 2010-09-15 12:15 UTC Modified: 2010-09-15 12:29 UTC
From: fh-phpbug2 at fholzhauer dot de Assigned: aharvey (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3.3 OS: osx
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: fh-phpbug2 at fholzhauer dot de
New email:
PHP Version: OS:

 

 [2010-09-15 12:15 UTC] 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)
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-15 12:20 UTC] aharvey@php.net
-Status: Open +Status: Assigned -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: aharvey
 [2010-09-15 12:20 UTC] 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:29 UTC] 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:29 UTC] aharvey@php.net
-Status: Assigned +Status: Closed
 [2010-09-15 12:29 UTC] aharvey@php.net
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.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 21:00:02 2026 UTC