Try array_merge()
Regards,
Andrey Hristov
----- Original Message -----
From: "Marc Logghe" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]