Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php for loop variable names

i got a code of 100-200 rules for making a table. but the whole time is happening the same. i got a variable $xm3, then i make a column . next row, i got $xm2 and make column. next row, i got $xm1 and make column.

so my variables are going to $xm3, $xm2, $xm1, $xm0, $xp1, $xp2, $xp3.

is there a way to make a forloop so i can fill $xm and after that a value from the for loop?

like image 880
Stefan Avatar asked Aug 24 '26 14:08

Stefan


1 Answers

In this kind of structure you'd be better off using an array for these kinds of values, but if you want to make a loop to go through them:

for($i = 0; $i <= 3; $i++) {
    $var = 'xm' . $i
    $$var; //make column stuff, first time this will be xm0, then xm1, etc.

}
like image 147
GSto Avatar answered Aug 26 '26 05:08

GSto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!