Bug #18075 Updated: array_merge() redefines numeric keys

From: Date: Tue, 02 Jul 2002 20:04:08 +0000
Subject: Bug #18075 Updated: array_merge() redefines numeric keys
References: 1  Groups: php.bugs php.doc 
Request: Send a blank email to php-bugs+get-12856@lists.php.net to get a copy of this message
ID: 18075 Updated by: eru@php.net Reported By: nepto@pobox.sk -Status: Open +Status: Bogus Bug Type: Documentation problem Operating System: Linux, FreeBSD PHP Version: 4.1.2 New Comment: See example 2 on the manual-page, the sentence after the first code-box: "Don't forget that numeric keys will be renumbered!" The next sentence reads: "If you want to completely preserve the arrays and just want to append them to each other, use the + operator." Previous Comments: ------------------------------------------------------------------------ [2002-06-30 17:22:17] derick@php.net But it is a documentation problem... reclassifying ------------------------------------------------------------------------ [2002-06-30 16:14:22] nepto@pobox.sk Lets consider that we have following arrays, $ar1 and $ar2: // first array $ar1 = array(); $ar1[1] = 'val1'; $ar1[2] = 'val2'; // second array $ar2 = array('key' => ''); Than we have resulting array $res. Let's lookwhat happend after array_merge() call: $res = array_merge($ar1, $ar2); var_dump($res); Resulting array is described here: array(3) { [0]=> string(4) "val1" [1]=> string(4) "val2" ["key"]=> string(0) "" } Numeric keys 1 and 2 was recoded to 0 and 1. Looks like bug, isn't it? I refer to the documentation, but there is nothing written about the numeric keys redefining. An exaple there (in documentation) shows example, where only numeric keys started from 0 are used, so no such change happened. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=18075&edit=1

« previous php.bugs (#12856) next »