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 Commented 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};
} 
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, i'll use an array then, and your answer is working, so thanks again!
0

try it.

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

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

?>

1 Comment

replace with variable which one you want concatenate.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.