Re: unshift a key value pair
| From: | Andrey Hristov | Date: | Wed, 09 Jan 2002 11:17:41 +0000 |
| Subject: | Re: unshift a key value pair | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-79892@lists.php.net to get a copy of this message | ||
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
>
>