echo PHP中的两个变量

时间:2017-04-14 12:50:34

标签: php

我有这个循环,我想在循环

中显示问题$ vari2的值
            $vari1=$_SESSION['quantity'];
            $vari2=0;
            while($vari2<$vari1){
                $vari2++;
                extract( $_POST, EXTR_OVERWRITE, "question$vari2" );
                echo "<br>data1= ".$_SESSION['data1'.$vari2];
                echo "<br>data2= ".$_SESSION['data2'.$vari2];
                echo "<br>data3= "."$question1"."<br>"; //problem with this line
            }

如何写最后一行来显示问题1,问题2 ...在循环中我尝试echo '$'.'question'.$vari2;但这显示文件中的$ question2而不是此变量的值

1 个答案:

答案 0 :(得分:0)

您很可能正在寻找variables variable

$var = "question{$vari2}";
echo "<br>data3={$$var}<br>";