Thanks to this post «Dynamic variable names in PHP» for enlightening me on how easy this is. There’s a lot of stuff out there about PHP variable variables but if you just want to craft a variable’s name based on some other variables that are already set – this is the way to go.
$var = "FooBar";
$extended_FooBar = "An Extension of FooBar";
echo ${"extended_{$var}"} ;
Basically a regular variable with lots of curly braces and – in this case – not a dot concatenation operator in sight.
So simple when you know how.
Last updated on 5th septiembre 2018
Deja un comentario