Re: unshift a key value pair

From: Date: Wed, 09 Jan 2002 11:27:53 +0000
Subject: Re: unshift a key value pair
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-79894@lists.php.net to get a copy of this message
That's exactly what I did to make it work I gave up playing with array_unshift. Thanks anyway. Marc "Andrey Hristov" <ahristov@icygen.com> wrote in message news:087501c198ff$45961270$0b01a8c0@ANDreY... > Try array_merge() > > > Regards, > Andrey Hristov > ----- Original Message ----- > From: "Marc Logghe" <marc.nospam.logghe@devgen.com> > To: <php-general@lists.php.net> > Sent: Wednesday, January 09, 2002 10:55 AM > Subject: [PHP] unshift a key value pair > > > > Hi, > > I was wondering how you could unshift a key value pair onto an array. > > In the manual one suggested using a function like this: > > function array_unshift_assoc(&$arr, $key, $val) > > { > > $arr = array_reverse($arr, true); > > $arr[$key] = $val; > > $arr = array_reverse($arr, true); > > return count($arr); > > } > > it is a nice trick but this did not really convince me. > > When you have eg an array like this: $a = array("foo"=>"bar", > > "foo2"=>"bar2") and you do an array_shift operation, > > you end up with ("foo2"=>"bar2"). So it is really easy to *remove* > > a > > key-value > > pair, but how do you put one in ? > > Marc > > > > > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > >

« previous php.general (#79894) next »