PHP $ Variable:
The single dollar PHP Variables ($x, where x is the variable name) are the normal variables that temporarily stores its data to a memory location.
PHP $$ Variable:
The double dollar PHP Variables ($$x, where x is the variable name) are the reference variables that are used to store the value of the single dollar variable ($x) inside it.
Example 1: Printing values of $ Variable, $$ Variable and value of $ variable using PHP Echo Statement
<!DOCTYPE html> <html> <body> <?php $v = "xyz"; $$v = 500; echo $v. "<br>"; echo $$v. "<br>"; echo $xyz; ?> </body> </html> |
Example 2: Printing value of $ and $$ Variables in a single message.
<!DOCTYPE html> <html> <body> <?php $v = "xyz"; $$v = 500; echo $v. "<br>"; echo $$v. "<br>"; echo "Value of $v is:” .$$v; ?> </body> </html> |