php for loop variable names

后端 未结 5 1476
北恋
北恋 2021-01-21 01:22

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. n

5条回答
  •  萌比男神i
    2021-01-21 01:44

    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.
    
    }
    

提交回复
热议问题