Home >Backend Development >PHP Tutorial >How Does PHP's `$$` (Double Dollar) Notation Work with Variable Variables?
PHP's Variable Variables: Decoding $$ (Double Dollar)
When encountering the $$ notation within PHP, it's essential to delve into the concept of variable variables. This syntax, denoted as $$variable, allows you to access and manipulate variables whose names are stored in other variables.
Imagine the following code snippet within a function:
global $$link;
Here, $$link represents a variable variable, where $$ indicates that the variable name itself is stored in the $link variable. Consider the following example:
$real_variable = 'test'; $name = 'real_variable'; echo $$name; // Outputs: 'test'
In this case:
Note that this mechanism can extend beyond "double variables." For example:
$real_variable = 'test'; $name = 'real_variable'; $name_of_name = 'name'; echo $$name_of_name; // Outputs: 'real_variable' echo $$$name_of_name; // Outputs: 'test'
Here, $$$name_of_name navigates one level deeper, accessing the variable whose name is stored in the variable named by $name_of_name.
The above is the detailed content of How Does PHP's `$$` (Double Dollar) Notation Work with Variable Variables?. For more information, please follow other related articles on the PHP Chinese website!