简体   繁体   中英

PHP a concatenate variable issue

I'm trying to concatenate several variables following http://php.net/manual/en/language.variables.variable.php but I don't get why it's not working

<?PHP

$test1 = 'test1';
$test2 = 'test2';
$test0 = 'test0';

for($i=1;$i<=9;$i++){
    $j = $i%3;
    echo ${$test.$j};
}

?>

If at all possible it would be much easier to just set the variables up as an array in the first place.

But to do what you are trying do this

$test1 = 'test1';
$test2 = 'test2';
$test0 = 'test0';

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

try it.

  $test1 = 'test1';
  $test2 = 'test2';
  $test0 = 'test0';

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

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM