Re: referencing an array element with a string variable
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: referencing an array element with a string variable

From: Bosconian <bosconian@planetx.com>
Date: Wed Jul 20 2005 - 03:26:23 CEST

"Ken Robinson" <kenrbnsn@rbnsn.com> wrote in message
news:1121746343.422353.202300@g47g2000cwa.googlegroups.com...
>
>
> Bosconian wrote:
> > I've been researching this for hours and can't seem to find the right
> > syntax.
> >
> > I need to retrieve a value of an array by referencing the element using
a
> > string variable.
> >
> > For example:
> >
> > $data['lastname'] = 'hank';
> > $element = 'lastname';
> > echo $data[$element];
> >
> > Outputs:
> >
> > hank
> >
> > Seems straightforward enough, but the solution escapes me.
>
> That should work fine. What problems are you encountering? What are you
> trying to do?
>
> Ken
>

Thanks to all who responded.

Turns out the syntax was correct (as noted.) My array was in fact not being
defined correctly so the element was therefore empty.

Sorry for wasting your time.
Received on Mon Oct 17 21:11:52 2005