2

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};
}

?>
1
  • 3
    i don't see $colonne defined Jun 11, 2013 at 13:55

2 Answers 2

4

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};
} 
1
  • thanks, i'll use an array then, and your answer is working, so thanks again! Jun 11, 2013 at 14:00
0

try it.

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

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

?>

1
  • replace with variable which one you want concatenate. Jun 11, 2013 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.