-2

PHP - How to concatenation 2 php var for create a new php var?

I want to concatenation $test with $i for create a new php var.

like this but not work, how can i do ?

<?PHP
$i = "5";
$test_$i = "WELCOME";
echo $test_5;
?>

1 Answers1

2

You have to use variable variables :

<?php
    $i = "5";
    ${'test_' . $i} = "WELCOME";
    echo $test_5; // echoes "WELCOME"
?>
roberto06
  • 3,844
  • 1
  • 18
  • 29