RE: [PHP] variable variables

From: Date: Thu, 17 Jan 2002 16:32:05 +0000
Subject: RE: [PHP] variable variables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-80929@lists.php.net to get a copy of this message
there's one example of var-of-vars along with arrays below my rant <rant> var-of-var is almost always an evil thing. there are some rare instances where they're necessary, but i assure you that your script would be MUCH cleaner and easier to modify in the future if you used a simple array. compare: $value = $form[$temp . $i]; to: eval('$valueofsize = $'. $temp . $i .';'); </rant> $form['size1'] = "hey"; $form['size2'] = "there"; $size1 = "hey"; $size2 = "there"; $loopcounter = 2; while ($i++ < $loopcounter) { $temp = "size"; eval('$valueofsize = $'. $temp . $i .';'); print $valueofsize; print $form[$temp . $i]; } ---------------- Scott Hurring - Internet Programmer GraphicType Services tel: 973.667.9486 web: http://www.graphictype.com/ pgp: http://graphictype.com/scott/pgp.txt ---------------- > -----Original Message----- > From: Mike Krisher [mailto:mike@twopeoplecommunicating.com] > Sent: Thursday, January 17, 2002 11:12 AM > To: php-general@lists.php.net > Subject: [PHP] variable variables > > > I can not wrap my head around variable variables today, not awake yet or > something. > > For instance I trying something like this: > > while ($i<$loopcounter) { > $temp = "size"; > $valueofsize = $$temp$i; > $i++; > } > > this doesn't work obviously, $valueofsize ends up with a literal value of > "$size1". But I need it to equal the value of a variable named $size1. Do I > need to use a eval() or something? > > Thanks in advance, > » Michael Krisher > mike@hyperquake.com > > > -- > 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 > >

« previous php.general (#80929) next »