Say I had the variable $foo
which has a value of "bar"
and I wanted to make a variable variable from it, but also append the string "123"
to it, so that the variable name is $bar123
. How would I do this?
I already know that $$foo = "abc123"
would make a variable $bar
with the value of "abc123"
, but I don't know how to append a string to this variable name.
I realised the solution was fairly simple:
$foo = "bar";
$x = $foo . "123"
$$x = "random important variable value"