Re: Array merge changes VALUE of keys, never mind the type

From: Date: Fri, 28 Sep 2001 18:58:38 +0000
Subject: Re: Array merge changes VALUE of keys, never mind the type
References: 1 2  Groups: php.dev 
Request: Send a blank email to php-dev+get-66784@lists.php.net to get a copy of this message
On Fri, 28 Sep 2001, Nick Lindridge wrote: > > array_merge() does *not* change the value of keys. Period. > > Sigh, yes it does. And below is the simple proof. I should have said, does not change the type of keys. > <? // -*- c -*- > > $arr1 = array(1=>'one'); > $arr2 = array(2=>'two'); > > print_r(array_merge($arr1, $arr2)); > > ?> > > gives: > > Array ( [0] => one [1] => two ) > > Please tell me in what way this hasn't changed the > keys. Yes, array_merge() is meant to simply concatenate two arrays together, one after the other, so it _has_ to renumber the numeric keys. To do what you want, use the + operator on the arrays. > Derrick and your response andrei are very > disappointing. I guess you just have to live with it. -Andrei As I was going up the stair, I met a man who wasn't there. He wasn't there again today. I wish, I wish he'd stay away. -Hughes Mearns

« previous php.dev (#66784) next »