RE: [PHP] if $index=1 how can I create a variable named $column_1
| From: | ..s.c.o.t.t.. [gts] | Date: | Thu, 10 May 2001 15:07:16 +0000 |
| Subject: | RE: [PHP] if $index=1 how can I create a variable named $column_1 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-52296@lists.php.net to get a copy of this message | ||
And even though it's much less elegant than the
solution by Sean below, you could also use 'eval'
$toast = array("wheat", "rye", "pumpernickel");
$numbreads = count($toast);
for ($index = 0; $index < $numbreads; $index++) {
eval("\$column$index = '$toast[$index]';
echo \$column$index . '<BR>';") ;
}
> -----Original Message-----
> From: Sean R. Bright [mailto:elixer@erols.com]
> To: 'Jay Lepore'; php-general@lists.php.net
> Subject: RE: [PHP] if $index=1 how can I create a variable named
>
> $toast = array("wheat", "rye", "pumpernickel");
> $numbreads = count($toast);
> for ($index = 0; $index < $numbreads; $index++) {
> ${"column" . $index} = $toasts[$index];
> }
>
> (A little less code and one less variable required.)
>
> Sean