我有多个PHP变量,格式为
$number1, $number2, $number3 and so on...
我想在循环内动态引用这些来从中检索信息,但我不确定如何动态引用静态变量。例如:
for($i = 1; $i <= 10; $i++) {
//The first number to be printed should be the value from
//$number1 not $number concatenated to $i
//here are some of the strings I tried:
echo "$number$i";
echo "{$number}$i";
echo "{$number}{$i}";
}
答案 0 :(得分:6)
这应该这样做:
echo ${"number{$i}"};
但为什么不使用数组呢?让$number[$i]
更具可读性......