In this trick, we will learn what is variables variable in PHP or you can say double dollar ($$) or references variable.
$x single dollar is a normal variable in PHP where
x is the name of the variable and you can hold the value in this variable.
$$x double dollar is a reference variable that stores the value which means the $ symbol holds the value of
$x and you can access it by adding the
$ prefix of the original variable (
Variable’s Variable in PHP – Double Dollar ($$)
Using the double dollar (
$$) variable, you can access the value of other reference variables. The syntax of using the double dollar variable (
$$variable) is also called the variables variable in PHP.
Let’s see how we can use it.
Here is the explanation:
$original_variablevariable hold the text “YourBlogCoach“
$namecontain the name of the variable “original_variable“
$$namemeans that the variable that has its name contained in
$nameand that reference is
$original_variablewhich has the value text.
Let’s take another real-world example, which gives you a better understanding of using the double dollar reference variable in PHP.
Mohit study in Computer Science
Being Tricky 😉