php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38266 array += operator broken
Submitted: 2006-07-31 08:38 UTC Modified: 2006-07-31 10:48 UTC
From: jason at jasonjustman dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.4.2 OS: linux/windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
42 + 8 = ?
Subscribe to this entry?

 
 [2006-07-31 08:38 UTC] jason at jasonjustman dot com
Description:
------------
array += operator is now broken in 4.4.1 and 4.4.2

Reproduce code:
---------------
<?
$x = array("a","b","c");
$x +=array("d","e");
print_r($x);


Expected result:
----------------
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e)

Actual result:
--------------
Array ( [0] => a [1] => b [2] => c )

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-31 08:51 UTC] tony2001@php.net
This is how it works in 4.3.0, 4.3.6, 4.3.11, 5.0.x.
No bug here.
 [2006-07-31 10:48 UTC] jason at jasonjustman dot com
Please refer to the following docs page:

< http://us3.php.net/manual/en/function.array-merge.php >

If you want to completely preserve the arrays and just want to append them to each other, use the + operator:
<?php
$array1 = array();
$array2 = array(1 => "data");
$result = $array1 + $array2;
?> 

i know that array_merge is the proper function to use in my previous test case, for the output. but, regardless, if the key association is being maintaed in my previous test case, the output should really be [0] => d [1]=>e [2]=>c


please revisit, or redoc on the manpage.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 21:01:29 2024 UTC