#27162 [Opn->Bgs]: Bad int keys generated by array_merge_recursive
| From: | iliaa@php.net | Date: | Fri, 06 Feb 2004 02:48:17 +0000 |
| Subject: | #27162 [Opn->Bgs]: Bad int keys generated by array_merge_recursive | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-54493@lists.php.net to get a copy of this message | ||
ID: 27162
Updated by: iliaa@php.net
Reported By: tomas dot matousek at matfyz dot cz
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: WinXP
PHP Version: 5.0.0b3 (beta3)
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
This is to be expected. Indexing of any array always starts
from element 0 and is not carried over across array
dimensions.
Previous Comments:
------------------------------------------------------------------------
[2004-02-05 14:49:07] tomas dot matousek at matfyz dot cz
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 this bug report at http://bugs.php.net/?id=27162&edit=1