<?php
$number = 1;
${'str_'.$number} = 'foobar';
echo $str_1;//foobar
How to set a variable to a string?
Pregunta
There is any possibility making something like that using PHP?
<?php
$number = 1;
$str_$number = "BlahBlah";
// and make this: $str_1 = "BlahBlah";
echo $str_1;
?>
Solución
Otros consejos
<?php
$number = 1;
$value = 'str_' . $number;
$$value = 'blahblah';
echo $str_1;
?>
Try
<?php
$number = 1;
${'str_' . $number} = 'foobar';
?>
You can also try
$number = 1;
eval('$str_'.$number.' = "foobar";');
echo $str_1;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow