Bug #13478 Updated: array_merge changes keys
| From: | derick@php.net | Date: | Fri, 28 Sep 2001 12:28:15 +0000 |
| Subject: | Bug #13478 Updated: array_merge changes keys | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-66766@lists.php.net to get a copy of this message | ||
ID: 13478
Updated by: derick
Reported By: nick@macaw.demon.co.uk
Old Status: Open
Status: Bogus
Bug Type: Arrays related
Operating System:
PHP Version: 4.0.6
New Comment:
This is not a bug, but a feature. All string indexes are converted to numbers if possible, even like
this:
<?php
$a = array ('4' => "test");
print_r ($a);
?>
will show:
Array
(
[4] => test
)
Making it bogus
Previous Comments:
------------------------------------------------------------------------
[2001-09-28 08:19:02] nick@macaw.demon.co.uk
Found in 4.0.7RC2 but probably present before. Array merge changes keys that are string-numeric.
e.g.
<?
$arr1 = array('1'=>'one', '2'=>'two');
$arr2 = array('a'=>'all');
print_r(array_merge($arr1, $arr2));
?>
gives:
Array ( [0] => one [1] => two [a] => all )
A workaround kludge is to prefix string-numeric keys with a letter.
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=13478&edit=1