From:             tomas dot matousek at matfyz dot cz
Operating system: WinXP
PHP version:      5.0.0b3 (beta3)
PHP Bug Type:     Arrays related
Bug description:  Bad int keys generated by array_merge_recursive

Description:
------------
Function array_merge_recursive merges arrays recursivelly but the behavior
of merging is different in the first level from the next ones.

Merging of arrays in the second and next levels starts key indexing from
the key of the first item merged but on the first level it starts always
from zero.

Maybe it is a feature but IMHO it would be better to implement the same
behavior on each level of a recursion.


Reproduce code:
---------------
    $ar1 = array(4=>4, 5=>5);
    $ar2 = array(4=>4, 5=>5);

    print_r(array_merge_recursive($ar1, $ar2)); 

    $ar1 = array("a" => array(4=>4, 5=>5));
    $ar2 = array("a" => array(4=>4, 5=>5));

    print_r(array_merge_recursive($ar1, $ar2)); 

    $ar1 = array("a" => array("a" => array(4=>4, 5=>5)));
    $ar2 = array("a" => array("a" => array(4=>4, 5=>5)));

    print_r(array_merge_recursive($ar1, $ar2)); 


Expected result:
----------------
Array
(
    [0] => 4
    [1] => 5
    [2] => 4
    [3] => 5
)
Array
(
    [a] => Array
        (
            [0] => 4
            [1] => 5
            [2] => 4
            [3] => 5
        )

)
Array
(
    [a] => Array
        (
            [a] => Array
                (
                    [0] => 4
                    [1] => 5
                    [2] => 4
                    [3] => 5
                )

        )

)



Actual result:
--------------
Array
(
    [0] => 4
    [1] => 5
    [2] => 4
    [3] => 5
)
Array
(
    [a] => Array
        (
            [4] => 4
            [5] => 5
            [6] => 4
            [7] => 5
        )

)
Array
(
    [a] => Array
        (
            [a] => Array
                (
                    [4] => 4
                    [5] => 5
                    [6] => 4
                    [7] => 5
                )

        )

)



-- 
Edit bug report at http://bugs.php.net/?id=27162&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=27162&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=27162&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=27162&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=27162&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=27162&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=27162&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=27162&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=27162&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=27162&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=27162&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=27162&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=27162&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27162&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=27162&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=27162&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=27162&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27162&r=float

Reply via email to