RE: [PHP] dynamic variables in a while loop?
| From: | Ford, Mike [LSS] | Date: | Wed, 15 Jan 2003 13:09:37 +0000 |
| Subject: | RE: [PHP] dynamic variables in a while loop? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-131693@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Philipp Hartmann [mailto:heart@gsdh.org]
> Sent: 15 January 2003 12:50
>
> Here is what I want to do:
> I am getting several variables into a Php Script such as:
>
> help1 = "yes" / "no"
> help2 = "yes" / "no"
> .
> .
> .
> helpX = "yes" / "no"
>
> I need to check whether the variable is true or false, and
> according to that
> add
> 1 to a counter variable.
>
> Something like this I'd do in ActionScript, but dont know about php
> [CODE]
> $i = 0;
> While (++$i <= 8) {
> if ([help]+$i=="yes"){ // this line produces an error...
I think you need to read the PHP manual page on variable variables:
http://www.php.net/manual/en/language.variables.variable.php
-- and the one
on string operators:
http://www.php.net/manual/en/language.operators.string.php
> $counterYes += counterYes;
I assume this is a typo for $counterYes += 1 ...!
> }
> }
> [/CODE]
>
> Do I have to initialize all variables before I can use them in php?
No -- but, presuming these values are coming from a form, or a query on the
URL, the other thing you need to take account of is the configuration
setting for register_globals. If it's on, then fine, the above will work
with appropriate amendments to suit PHP syntax; if it's off, then you have
to use the $_POST[] or $_GET[] array as appropriate, and in fact the
variable variables stuff is not relevant because the array index is just the
HelpX string.
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