php for循环变量名 [英] php for loop variable names
问题描述
我得到一张100-200条规则的代码来制作一张桌子.但整个过程都是一样的 我得到了一个变量$ xm3,然后我创建了一个专栏.在下一行,我得到了$ xm2并列为一列.在下一行,我得到了$ xm1并列为一列.
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.
所以我的变量将变为$ xm3,$ xm2,$ xm1,$ xm0,$ xp1,$ xp2,$ xp3.
so my variables are going to $xm3, $xm2, $xm1, $xm0, $xp1, $xp2, $xp3.
有没有办法制作一个forloop,以便我可以填充$ xm,然后从for循环中获取一个值?
is there a way to make a forloop so i can fill $xm and after that a value from the for loop?
推荐答案
在这种结构中,最好将数组用于这些类型的值,但是如果要循环遍历它们,则最好:
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.
}
这篇关于php for循环变量名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!