Re: Behaviour of $array1 + $array2

From: Date: Fri, 11 Jan 2002 04:27:08 +0000
Subject: Re: Behaviour of $array1 + $array2
References: 1 2  Groups: php.dev 
Request: Send a blank email to php-dev+get-76575@lists.php.net to get a copy of this message
On Fri, Jan 11, 2002 at 09:33:59AM +0900, Yasuo Ohgaki wrote : > Markus Fischer wrote: > > >Can someone point me where the following behaviour is documented: > > > > $ php -q > > <? > > $foo = array(27 => 'Ene'); > > $bar = array(-1 => 'Mene'); > > > > $baz = $foo + $bar; > > > > var_dump($baz); > > ?> > > array(2) { > > [27]=> > > string(3) "Ene" > > [-1]=> > > string(4) "Mene" > > } > > > >cheers > > > > - Markus > > > > > > I guess it's not. > > There is note explains this behavior. Accoding to the note, > "PHP Developer's Cookbook claims (p. 87 and sort of on p. 108) > that '+' is syntactic sugar for array_merge." Which is not true: $ php -q <? $foo = array(27 => 'Ene'); $bar = array(-1 => 'Mene'); $baz = array_merge($foo, $bar); var_dump($baz); ?> array(2) { [0]=> string(3) "Ene" [1]=> string(4) "Mene" } To make it short: array_merge is unable to preserve keys. -- Please always Cc to me when replying to me on the lists.

« previous php.dev (#76575) next »