In general, he frowned, as it makes the code much more difficult to read and follow, but you can use one variable value as another variable name:
$foo = "bar"; $baz = "foo"; echo $$baz; // will print "bar" $foofoo = "qux"; echo ${$baz . 'foo'}; // will print "qux"
See the PHP documentation for variable variables for more information.
However, as I mentioned, this can lead to very difficult to read code. Are you sure you can't just use an array?
$hello = array( "hello1", "hello2", // ... etc ); for($hello as $item) { echo $item . "<br>"; }
source share