Re: array_push() an associative array item
| From: | Peter Lockhart | Date: | Mon, 14 Aug 2000 12:11:19 +0000 |
| Subject: | Re: array_push() an associative array item | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-11583@lists.php.net to get a copy of this message | ||
----- Original Message -----
From: Robin Vickery <robin@planet-three.co.uk>
To: "Peter Lockhart" <peter@halcyon.co.za>
Sent: 14 August 2000 12:20
Subject: Re: [PHP] array_push() an associative array item
> peter@halcyon.co.za ("Peter Lockhart") writes:
>
> > Is it possible to use array_push() (or anything) to append an
associative
> > array item to an existing array ??
> >
> > ie I need to append "$key"=>"$val" onto an array, so that i can
> > then
access
> > $array($key); and get the associative $val value.
> >
> > I have tried a few combinations to get this to work with no luck.
> > none of the following work:
> >
> > array_push ($array, array($key, $value));
> > array_push ($array, "\"$key\" => \"$value\"");
> > array_push ($array, "$key => $val");
> >
> > etc etc.
> >
> > How can this get done ?
>
> $array[$key] = $value;
>
> Or am I completely missing the point?
No, I'm being a twit :)
In my defense, It was a 3am moment - trying to push assoc key=>items onto an
array when $array[$val[0]] = $val[1] works.
For background:
I'm parsing $QUERY_STRING, explode()ing it by "&" and then splitting each
form
element and it's associative value into an associative array within a loop,
so that I can
access the array by form element ($array[$form_element]) and get the
resultant
value.
*phew*
and after all that I find parse_url() ;)
Peter Lockhart
> -robin