Re: Variable array variables?

From: Date: Sun, 15 Oct 2000 04:53:26 +0000
Subject: Re: Variable array variables?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-20213@lists.php.net to get a copy of this message
I think this will do what you want. It prints out "Bill"... <? $foo = array ( 'bar' => array ( 'name' => 'Bill' ) ); $arr = '$foo'; $ind = '[bar][name]'; eval("\$sValue = $arr$ind;"); echo $sValue; ?> JRB LeagueOffice.com Fantasy Sports ------------------------------------------------------- http://www.leagueoffice.com as cool as fantasy sports get... ------------------------------------------------------- Lars Torben Wilson <torben@php.net> wrote: > > > I've been searching archives and the 'net all day--and my memory, but > that seems to be down at the moment--for this. Given an array like: > > $foo = array ( > 'bar' => array ( > 'name' => 'Bill' > ) > ); > > ...and strings like $arr = 'foo' and $ind = '[bar][name]' (format can > be changed if needed), what would be the best way of doing something > like: > > echo ${$arr . $ind}; > > I always get 'Undefined variable: foo[bar][name]...' > > This is PHP 4.0.4-dev, CVS from about 20 minutes ago. > > Is this simply beyond the parser's capabilities, or am I merely > missing an obvious syntax problem here? Either way, the answer will > make it into the manual. :) > > > Cheers and TIA, > > Torben > > -- > +----------------------------------------------------------------+ > |Torben Wilson <torben@php.net> Netmill iTech| > |http://www.coastnet.com/~torben > http://www.netmill.fi| > |Ph: 1 250 383-9735 torben@netmill.fi| > +----------------------------------------------------------------+ > -- ls

« previous php.general (#20213) next »