RE: [PHP] dynamically named variables?
| From: | Ford, Mike [LSS] | Date: | Thu, 23 May 2002 16:44:38 +0000 |
| Subject: | RE: [PHP] dynamically named variables? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-98940@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Nick Wilson [mailto:nick@explodingnet.com]
> Sent: 23 May 2002 17:32
>
> I've been looking at the php manual section on variable
> variables but I
> don't think i either a) understand it, or b) it isn't what I need.
>
> Here's the coup:
>
> I have a bunch of post vars, lets say $red, $green and $blue
> I want to loop through the post vars and create a variable callled
> $file_red, $file_green and $file_blue
Try this (untested!):
foreach($_POST as $key=>$value):
${"file_$key"} = $value;
endforeach;
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211