php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35494 Array merge problem
Submitted: 2005-11-30 17:20 UTC Modified: 2005-12-02 16:43 UTC
From: marek dot rybar at dial dot sk Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.1.1 OS: Windows, Linux
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:
47 + 17 = ?
Subscribe to this entry?

 
 [2005-11-30 17:20 UTC] marek dot rybar at dial dot sk
Description:
------------
When I merge two arrays using + operator, result is array only with the first array elements.

Reproduce code:
---------------
$arr1 = array(1, 2, 3);
$arr2 = array(5, 6, 7);
$arr = $arr1 + $arr2;

result $arr:
array(1, 2, 3)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-30 17:27 UTC] tony2001@php.net
Expected behaviour.
Use array_merge_recursive() to get the result you expect.
 [2005-12-02 16:43 UTC] marek dot rybar at dial dot sk
Why do you think that is bogus? If it's true, please remove from manual this passage:

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;
?>

because $result is $array1 not $array1 + $array2

:-((((((
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Dec 02 09:03:34 2021 UTC