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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 22:01:29 2024 UTC