NYCPHP Meetup

NYPHP.org

[nycphp-talk] Question about variable variables

Daniel Porcher danporcher at earthlink.net
Fri Feb 13 15:06:40 EST 2004


Is there a consensus about the use of variable variables?  I have a form
with multiple rows with the same fields that vary in name by a numeric
suffix.  It seems to me in the code example below that using a variable
variable is a little cleaner.   Is there a reason why I shouldn't use the
first method?


1) Using variable variables

foreach($array as $key => $value)
{

$field = $name . $key;
$$field = foo($_POST['$field']);

}

2) Using arrays

foreach($array as $key => $value)
{

$field = $name . $key;
$fieldarray[$key] = foo($_POST['$field']);

}


Thanks,

Dan

Daniel Porcher
President
Watershed Web Design

Phone: (609) 466-0266
Fax:   (609) 466-2701





More information about the talk mailing list