php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #51699 array_merge() reindexes multiple arrays - doc error
Submitted: 2010-04-30 01:41 UTC Modified: 2010-04-30 14:30 UTC
From: stevenrusch at gmail dot com Assigned: salathe (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: WinXp
Private report: No CVE-ID: None
 [2010-04-30 01:41 UTC] stevenrusch at gmail dot com
Description:
------------
The 3rd paragraph of documentation description states:
"If only one array is given and the array is numerically indexed, the keys get reindexed in a continuous way."

The "If only one array is given" is incorrect. I supplied two arrays, both numerically indexed, and the result was reindexed (as also shown in Example#3). The sentence implies this would not happen if multiple numerically indexed arrays were given because it says "if only one...". The documentation should state: "If one or more arrays are given in which all arrays contain only numeric keys, the array values are merged and the keys are reindexed starting with zero in a continuous way." or something to that effect.

I realize Example #3 somewhat shows this by supplying two arrays one of which is empty and it shows the reindex. It would still be nice if the wording in the description above matched this. As you guessed, I read the doc description, used it, debugged my problem, and THEN noticed Example #3.

Test script:
---------------
$array1 = array(10=>'Ten',11=>'eleven');
$array2 = array(5=>'five',16=>'sixteen');
var_dump(array_merge($array1,$array2));


Expected result:
----------------
array(4) { [10]=>  string(3) "Ten" 
           [11]=>  string(6) "eleven" 
           [5]=>  string(4) "five" 
           [16]=>  string(7) "sixteen" } 

Actual result:
--------------
array(4) { [0]=>  string(3) "Ten" 
           [1]=>  string(6) "eleven" 
           [2]=>  string(4) "five" 
           [3]=>  string(7) "sixteen" } 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-30 14:27 UTC] salathe@php.net
Automatic comment from SVN on behalf of salathe
Revision: http://svn.php.net/viewvc/?view=revision&revision=298804
Log: clarify array_merge reindexing behaviour with numeric-only keys (bug #51699)
 [2010-04-30 14:30 UTC] salathe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: salathe
 [2010-04-30 14:30 UTC] salathe@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.

That sentence has been rephrased to read, "If all of the arrays contain only 
numeric keys, the resulting array is given incrementing keys starting from zero." 
Hopefully that makes more sense; please give feedback if not.  Thank you for your 
report.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 05:00:01 2026 UTC