0

I need to combine and show variable but now not show variable;

I need to combine and show variable but now not show variable; someone can help me fix it someone can help me fix it

$ab1 = 20;
$ab2 = 30;

$x = 1;
while ($x < 3){


echo '$ab'.$x;

$x++;} 

result $ab1 $ab2 / I need to show variable

2 Answers2

0

You can use ${} to create dynamic variable name, so do:

echo ${'ab'.$x};
Mohsen Nazari
  • 1,281
  • 1
  • 3
  • 13
0

Try this it should help

$ab1 = 20;
$ab2 = 30;    

$x = 1;

while ($x < 3){

$result = ${'ab'.$x};

echo $result . PHP_EOL; 

$x++;
}