RE: [PHP] dynamically named variables?

2002-05-23 Thread Ford, Mike [LSS]

 -Original Message-
 From: Nick Wilson [mailto:[EMAIL PROTECTED]]
 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: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] dynamically named variables?

2002-05-23 Thread Nick Wilson

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


* 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



-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.6 (GNU/Linux)

iD8DBQE87SRcHpvrrTa6L5oRAuAEAKCYTILrONLQwz82LCQzeHoFAEbIrgCgrlE+
I1WGK+d9Fpu2nFOqOYxFnqk=
=r91v
-END PGP SIGNATURE-

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] dynamically named variables?

2002-05-23 Thread Rasmus Lerdorf

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) [EMAIL PROTECTED]
 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
 --



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] dynamically named variables?

2002-05-23 Thread Philip Olson


   extract($_POST, EXTR_PREFIX_ALL, 'file_');

A little typo, extract() automatically attaches 
a '_' so the third parameter here would be just 
'file'.  

This behavior is unlike import_request_variables() 
and I assume the behavior remains for historical 
reasons.  Kinda odd.

Regards,
Philip Olson


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php