php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #52048 array_merge_recursive not make it clear if former or latter takes precedenence
Submitted: 2010-06-11 11:33 UTC Modified: 2010-09-08 17:03 UTC
From: matt at mediaequals dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: all
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: matt at mediaequals dot com
New email:
PHP Version: OS:

 

 [2010-06-11 11:33 UTC] matt at mediaequals dot com
Description:
------------
The array_merge documentation includes the essential words

"If the input arrays have the same string keys, then the later value for that key will overwrite the previous one."

A similar statement does not exist for array_merge_recursive.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-08 17:03 UTC] cataphract@php.net
-Status: Open +Status: Bogus
 [2010-09-08 17:03 UTC] cataphract@php.net
That's because the behavior of the two differ in that aspect:

<?php
$arr1 = array("a"=>1);
$arr2 = array("a"=>2);
print_r(array_merge($arr1,$arr2));
print_r(array_merge_recursive($arr1,$arr2));

gives

Array
(
    [a] => 2
)
Array
(
    [a] => Array
        (
            [0] => 1
            [1] => 2
        )

)

This is clearly explained in the docs for array_merge_recursive, including the example.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 14:01:34 2025 UTC