NYCPHP Meetup

NYPHP.org

[nycphp-talk] follow-on variable variables question

Joel De Gan joel at tagword.com
Fri Feb 13 17:02:48 EST 2004


The PHP site has good info at
http://us4.php.net/language.variables.variable

I don't use personally use them exactly like that.. But for forms when
you have an unknown number of items in say a radio group, they are
invaluable.

i.e.
<?
# to output
for($a=0;$a<5;$a++){
	echo "<input type='radio' name=radio_$a value=$a>\n";
}

#to read
for($a=0;$a<5;$a++){
	$reading = ${"radio_".$a}; // reading the variable variable
	#do something with $reading if it <> ""...
}
?>

That is just about the only way I ever use them, and commonly do use
them. However, the methods in the php.net examples would only serve to
confuse..

-Joel De Gan

On Fri, 2004-02-13 at 16:50, James Wetterau wrote:
> Based on my experience with Perl, I would have stayed away from
> variable variables, since the same tool in Perl (using a variable
> value as another variable's name) is Frowned Upon by Those in the
> Know.
> 
> Here's a cogent summary of the issues the practice raises in Perl:
> 
> http://perl.plover.com/varvarname.html
> 
> Anyone care to explain what, if anything, is different in PHP?
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
-- 
joeldg - developer, Intercosmos media group.
http://lucifer.intercosmos.net




More information about the talk mailing list