dynamic variables


Hey, I’m new here :D

For a php file I am working on I need to make some dynamic varaibles. What i mean is that I have many variables called $F1,$F2,$F3 and so on. Then I want to output each one of these. instead of using print($F1) print($F2) I try to use a for loop:

print("$F".$i);//this is supposed to output the variable $F1 if $i=1


It’s not supposed to work that way, it’s only how you expect it to be. Use something like ${‘F’ . $i}, you will have more luck.


Thank you :D

I knew there was a way to do it, but I wasn’t sure of how. Do you know how I could make dynamic variables too? like if I wanted to make $F1 to $F10 ?


you have the right idea.

for ($i=1, $i<$someNum, $i++)
echo ${‘F’ . $i};

you could also try
echo {${‘F’ . $i}}
Though I don’t think you need to add the second set of curly braces