Re: Bug #13478 Updated: array_merge changes keys

From: Date: Sun, 30 Sep 2001 12:34:35 +0000
Subject: Re: Bug #13478 Updated: array_merge changes keys
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-66853@lists.php.net to get a copy of this message
On Fri, 28 Sep 2001, Markus Fischer wrote: > What a nasty 'feature'. Can't we get rid of it ASAP? Not really, it's how the Zend hash tables work. Every numeric key gets converted to a number, even if it's used as a string value. Derick > > It would allow comfty hash non-alpha key/value > inserting(reassembling) > > - Markus > > On Fri, Sep 28, 2001 at 12:28:15PM -0000, derick@php.net wrote : > > 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 > > > > > > -- > > PHP Development Mailing List <http://www.php.net/> > > To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net > > For additional commands, e-mail: php-dev-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > -- > Markus Fischer, http://guru.josefine.at/~mfischer/ > EMail: mfischer@guru.josefine.at > PGP Public Key: http://guru.josefine.at/~mfischer/C2272BD0.asc > PGP Fingerprint: D3B0 DD4F E12B F911 3CE1 C2B5 D674 B445 C227 2BD0 > -All your scripts are belong to Zend- > Derick Rethans --------------------------------------------------------------------- PHP: Scripting the Web - www.php.net - derick@php.net SRM: Site Resource Manager - www.vl-srm.net ---------------------------------------------------------------------

« previous php.dev (#66853) next »