php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #42323 Details in array_merge page are wrong
Submitted: 2007-08-16 22:36 UTC Modified: 2007-08-17 02:04 UTC
From: kev at projectcolo dot org dot uk Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: N/A
Private report: No CVE-ID: None
 [2007-08-16 22:36 UTC] kev at projectcolo dot org dot uk
Description:
------------
The notes in Example 257 above are incorrect. It states:

If you want to completely preserve the arrays and just want to append them to each other, use the + operator

Check the array type page at http://www.php.net/manual/en/language.types.array.php which states differently. Duplicate keys are ignored with the + operator.

Reproduce code:
---------------
<?php

    $x = array('moon','sky');
    $y = array('rain','shine');

    var_dump($x + $y);
    var_dump(array_merge($x, $y));

?>


Expected result:
----------------
array(2) {
  [0]=>
  string(4) "moon"
  [1]=>
  string(3) "sky"
  ... more values
}
array(4) {
  [0]=>
  string(4) "moon"
  [1]=>
  string(3) "sky"
  [2]=>
  string(4) "rain"
  [3]=>
  string(5) "shine"
}


Actual result:
--------------
array(2) {
  [0]=>
  string(4) "moon"
  [1]=>
  string(3) "sky"
}
array(4) {
  [0]=>
  string(4) "moon"
  [1]=>
  string(3) "sky"
  [2]=>
  string(4) "rain"
  [3]=>
  string(5) "shine"
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-17 02:04 UTC] vrana@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.

"If you want to completely preserve the arrays and just want to append them to each other (not overwriting the previous keys), use the + operator"
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Nov 19 12:00:02 2025 UTC