bschwarting
asked on
PHP Variable in a Loop?
Is it possible to create 100's of variables with a loop? The loop I'm using really cuts down on the code in the page, but I lose all my variables that I need to reference. Here is what I was thinking.
if $variable < 365 {
$variablenumber = 1;
$variablename{$$variablenu mber} = (variablenumber + 1);
} else {
echo "all done";
}
Is this possible?
So, the result would be these answers:
$variablename1 = 1
$variablename2 = 2
$variablename3 = 3
...
$variablename365 = 365
if $variable < 365 {
$variablenumber = 1;
$variablename{$$variablenu
} else {
echo "all done";
}
Is this possible?
So, the result would be these answers:
$variablename1 = 1
$variablename2 = 2
$variablename3 = 3
...
$variablename365 = 365
I assume you've looked at an array... $var[$x].
But this should do what you wanted:
$GLOALS['varname'.$variabl enumber] = $variablenumber;
you'll get $varname1 = 1, $varname2 = 2,
and they are all globals.
http://us3.php.net/manual/en/reserved.variables.globals.php
But this should do what you wanted:
$GLOALS['varname'.$variabl
you'll get $varname1 = 1, $varname2 = 2,
and they are all globals.
http://us3.php.net/manual/en/reserved.variables.globals.php
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I could only get Michaels701 to work. Thanks all!
yes, that code will do what you asked.
however, still curious about the why you need that in your code?
it really looks like you are doing something wrong in your method...
however, still curious about the why you need that in your code?
it really looks like you are doing something wrong in your method...
ASKER
angel, I wouldn't doubt it. I'm just past a beginner on PHP.
why not a plain array?
Open in new window