可能重複:
Loop through variables with common name如何在do-while循環中動態更改我的順序變量? (PHP)
所以我有這些變量,即$ A1,A2 $,$ A3等..
在做while循環,是否可以根據增量$ i調用$ aXX變量?
$a1 = ...
$a2 = ...
...
$i = 1
do {
...
... echo $a(<--- here I want to change from 1 to 2, 3, etc according to $i-->)
$i++;
} while ($i < ....)
這是可能的,但似乎你最好使用一個數組而不是'$ aX'形式的變量。這就是他們在那裏。 – 2012-07-26 21:05:12
如果數組不滿足您的先決條件,則您= = $ current =「a $ i」; echo $$ current;' – madfriend 2012-07-26 21:07:38
@madfriend:'echo $ {'a'。 $ i};'也可以使用。 – 2012-07-26 21:08:47