Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP动态引用字符串文本中的变量_Php_Dynamic_String Literals - Fatal编程技术网

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

我在表单中有多个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}";
}
对于($i=1;$i这应该可以做到:

echo ${"number{$i}"};

但是为什么不改用数组呢?拥有
$number[$i]
的可读性要高得多…

谢谢,这很有效!我会使用数组,但我只需要更改一个已经在那里处理变量的函数。