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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jason at jasonjustman dot com
New email:
PHP Version: OS:

 

 [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: Sat Apr 20 02:01:29 2024 UTC