php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12480 array_merge_recursive() clobbers existing numeric keys
Submitted: 2001-07-31 05:14 UTC Modified: 2001-08-06 12:51 UTC
From: pgl at instinct dot org Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.0.6 OS: FreeBSD
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: pgl at instinct dot org
New email:
PHP Version: OS:

 

 [2001-07-31 05:14 UTC] pgl at instinct dot org
if any of the keys of the first level of arrays are
numeric, using array_merge_recursive() will renumber
them to start at 0. this destroys keys that are used
to record id numbers, etc.

[mini:pgl]:~/public_html $ cat test.php 
#!/usr/local/bin/php -q
<?
$b[a][4] = 1;
$a[3][4] = 2;
print_r(array_merge_recursive($a, $b));
?>

[mini:pgl]:~/public_html $ ./test.php 
Array
(
    [0] => Array
        (
            [4] => 2
        )

    [a] => Array
        (
            [4] => 1
        )
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-08-06 12:51 UTC] andrei@php.net
array_merge* functions are not meant to preserve numeric keys.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 10:01:33 2025 UTC