PHP有连接变量的问题


PHP a concatenate variable issue

我试图连接以下http://php.net/manual/en/language.variables.variable.php几个变量,但我不明白为什么它不工作

<?PHP
$test1 = 'test1';
$test2 = 'test2';
$test0 = 'test0';
for($i=1;$i<=9;$i++){
    $j = $i%3;
    echo ${$test.$j};
}
?>

如果可能的话,首先将变量设置为数组会容易得多。

但是要做你想做的事情

$test1 = 'test1';
$test2 = 'test2';
$test0 = 'test0';
for($i=1;$i<=9;$i++){
    $j = $i%3;
    echo ${"test".$j};
} 

试一试。

  $test1 = 'test1';
  $test2 = 'test2';
  $test0 = 'test0';
for($i=1;$i<=9;$i++){
$j = $i%3;
echo $colonne.$j;
}

?>