Re: dynamically named variables?

From: Date: Thu, 23 May 2002 17:17:12 +0000
Subject: Re: dynamically named variables?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-98952@lists.php.net to get a copy of this message
Or you could simply use: extract($_POST, EXTR_PREFIX_ALL, 'file_'); That does the same thing much quicker. -Rasmus On Thu, 23 May 2002, Nick Wilson wrote: > > * and then Ford, Mike [LSS] declared.... > > > 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; > > Worked a treat, cheers Mike! > -- > Nick Wilson // www.explodingnet.com > > > > > ---------------------------------------------------------------------- > gpg: Warning: using insecure memory! > gpg: Signature made Thu 23 May 2002 10:18:20 AM PDT using DSA key ID 36BA2F9A > gpg: Good signature from "Nick Wilson (knickerlas) <nick@explodingnet.com>" > gpg: WARNING: This key is not certified with a trusted signature! > gpg: There is no indication that the signature belongs to the owner. > gpg: Fingerprint: 35DF 412F 4CCD 348D EA12 F134 1E9B EBAD 36BA 2F9A > ---------------------------------------------------------------------- >

« previous php.general (#98952) next »