Difference between $var and $$var in PHP
In PHP, $var is used to store the value of the variable like Integer, String, boolean, character. $var is a variable and $$var stores the value of the variable inside it.
$variable = value;
- The $variable is the variable name
- The value is the initial value of the variable.
Example 1: This example stores and displays values with $.
$$var: $$var stores the value of $variable inside it.
$variable = "value"; $$variable = "new_value";
- $variable is the initial variable with the value.
- $$variable is used to hold another value.
We can get another value by using the $value of the first variable.
Example 2: PHP program to demonstrates $$var.
hello Hello php
Difference between Both: The variable $var is used to store the value of the variable and the variable $$val is used to store the reference of the variable.