We can dynamically create a variable name based on the other variable value! It is a concept called PHP Variable variables. It might be useful at certain cases, lets see how we do it. So, It will be like this,


"A variable takes the value of a other variable and assumes it is the name of that variable"

For example, Check this, This is a normal variable assignment:

Now, when the variable assigned with two dollar signs($), It takes the value of the variable and creates a new variable with that value.
echo $foo $good; //outputs "good boy";

With this, we can dynamically create new variable like this,
foreach($sd as $key => $val)
echo $jsu $jsv $jsw; //outputs "i like you"


Comments (0)
Leave a Comment

loader Posting your comment...