php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #14992 Behaviour of $array = $array1 + $array2; not documented
Submitted: 2002-01-11 05:04 UTC Modified: 2002-07-01 17:58 UTC
From: mfischer@php.net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.1.1 OS:
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: mfischer@php.net
New email:
PHP Version: OS:

 

 [2002-01-11 05:04 UTC] mfischer@php.net
The behaviour of the following code doens't seem to be documented:

<?
    $foo = array(27 => 'Ene');
    $bar = array(-1 => 'Mene');
    
    $baz = $foo + $bar;

    var_dump($baz);
?>

array(2) {
  [27]=>
  string(3) "Ene"
  [-1]=>
  string(4) "Mene"
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-11 06:03 UTC] philip@php.net
Where should this feature be documented, I see two viable options:

a) Under array_merge()
b) A new "Array Operators" man page. 

I assume most people wanting to merge arrays will go to array_merge() but having it's own man page could make room to clearly explain the differences of it and array_merge and array_merge_recursive.  I vote for (b).  Of course the functions would link to it.  This is kinda like how `backticks` are documented now, as, "Execution Operators".

A brief note under "Arithmetic Operators" may be appropriate too.

Also, for those interested in documenting this beast, please see this post:

http://marc.theaimsgroup.com/?l=phpdoc&m=101074306518514
 [2002-01-16 12:53 UTC] andrei@php.net
$array1 + $array2 is *not* the same as array_merge(). See for yourself with array(1, 2) and array(5, 6, 7).
 [2002-01-16 14:44 UTC] philip@php.net
We know, but it needs to be documented nevertheless.  I posted a rather detailed test.  The question is "where" to document it exactly.
 [2002-06-29 13:03 UTC] steph dot fox at btinternet dot com
This is actually documented under array_merge() (was it always? - dunno) but omits to mention that shared keys will be overwritten on a first-come first-served basis.  Quick update, anyone with access?
 [2002-07-01 17:58 UTC] jan@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.


 [2020-02-07 06:12 UTC] phpdocbot@php.net
Automatic comment on behalf of jan
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=8cbc437a8e6cdc98ff98b64653663d7e2277f287
Log: - fix #14992
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 10 22:01:26 2024 UTC