We often use the $ symbol in PHP, so do you know the $$ symbol? The following article will take you to understand the $$ symbol, introduce what the $$ symbol is used in PHP, and how to use it. I hope it will be helpful to everyone.
The $$ symbol in PHP
In PHP, $var (single dollar) represents An ordinary variable named var, which stores any value such as string, integer, floating point, etc. And $$var (double dollar) is a reference variable used to store the value of $var. [Video tutorial recommendation:PHP tutorial]
Take an example to understand:
Use $var to store a String type value" PHP", and then use the reference variable $$var to store a String type value "PHP Chinese Network".
At this time, the value "Chinese Network" can be accessed in two ways:
1. Directly use reference variables. Example: echo $$var;
2. Access the value "PHP Chinese Network" by using the value "PHP" stored in the variable $var as the variable name. For example: echo $PHP; it will be output as "PHP Chinese Network" (without quotation marks).
Code example:
The following is an example of how to use $ and $ in PHP $:
Example 1:
"; // 输出$$var的值 echo $$var . "
"; // 输出$PHP的值 echo "$PHP"; ?>
Output:
Example 2:
"; echo ${$name}. "
"; echo $Cat. "
"; echo ${${$name}}. "
"; echo $Dog. "
"; ?>
Output:
The above is the entire content of this article, I hope it will be helpful to everyone's learning. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !
The above is the detailed content of What is the use of $$ symbol in PHP? how to use? (code example). For more information, please follow other related articles on the PHP Chinese website!