I have the following in a for loop over $x. $x
is from 1 to 100. I have variables t1
to t100
already assigned. I want to echo them without typing each one individually, hence the for loop, but the following does not work:
echo "<br>'$t.$x'";
How could I fix this?
You would have to combine the variable names:
echo ${"t".$x};
but this reeks of imperfect design. Why not use an array instead?
$varname = 't'.$x;
echo $$varname;
You can try something like:
$name = 't' . $x;
echo $$name;
Try:
for($x=1;$x<=100;$x++) {
echo '<br>'.${'t'.$x};
}