PHP动态引用字符串文本中的变量
我在表单中有多个PHP变量PHP动态引用字符串文本中的变量,php,dynamic,string-literals,Php,Dynamic,String Literals,我在表单中有多个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
$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}";
}
对于($i=1;$i这应该可以做到:
echo ${"number{$i}"};
但是为什么不改用数组呢?拥有$number[$i]
的可读性要高得多…谢谢,这很有效!我会使用数组,但我只需要更改一个已经在那里处理变量的函数。