RE: [PHP] Extracting Variables
| From: | Ford, Mike [LSS] | Date: | Thu, 13 Jun 2002 15:46:09 +0000 |
| Subject: | RE: [PHP] Extracting Variables | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-101978@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Steve Buehler [mailto:steve@vespro.com]
> Sent: 13 June 2002 15:54
>
> I hope that someone will be kind enough to help me on this.
<snip>
> I want to do something like the following, but it does not work:
> testinput();
> function testinput(){
> GLOBAL $HTTP_POST_VARS;
> extract($HTTP_POST_VARS);
> echo "i = $i<br>";
> for($c=1;$c<=$i;$c++){
> echo "team_number $team_number_$c<br>";
> echo "sub1_$c = $sub1_$c<br>";
> echo "sub2_$c = $sub2_$c<br>";
> echo "sub3_$c = $sub3_$c<br>";
> echo "sub4_$c = $sub4_$c<br>";
> echo "sub5_$c = $sub5_$c<br>";
> }
> }
I don't think you can do this directly in a single string (at least, I haven't been able
to!). However, either of the following formats should work for you:
echo "sub1_$c = " . ${"sub1_$c"} . '<br>';
echo "sub1_$c = " . ${'sub1_'.$c} . '<br>';
But -- erm -- can I just ask why you're not using arrays, which might make life somewhat
easier?!
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