php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #4522 Recursive array_merge() support
Submitted: 2000-05-19 13:43 UTC Modified: 2000-05-30 19:13 UTC
From: nathan at cjhunter dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0 Release Candidate 1 OS: Linux 2.2.14
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: nathan at cjhunter dot com
New email:
PHP Version: OS:

 

 [2000-05-19 13:43 UTC] nathan at cjhunter dot com
If a key from two arrays is the same in an array_merge() function, sub merge those two key's values. array_merge() currently just replaces the other key.

Here is an example of the current behavior.

$a = array("x" => array(1,2,3));
$b = array("x" => array(4,5,6));

var_dump(array_merge($a, $b));

----------------------------------

array(1) {
  ["x"]=>
  array(3) {
    [0]=>
    int(4)

    [1]=>
    int(5)

    [2]=>
    int(6)
  }
}
-------------

I would want it the output to be..

array(1) {
  ["x"]=>
  array(3) {
    [0]=>
    int(1)

    [1]=>
    int(2)

    [2]=>
    int(3)

    [3]=>
    int(4)

    [4]=>
    int(5)

    [5]=>
    int(6)
  }
}

Please mail me back with input. nathan@cjhunter.com

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-05-30 19:13 UTC] andrei at cvs dot php dot net
Implemented as array_merge_recursive().
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sun Jun 14 07:00:01 2026 UTC