PHP $ and $$ Variables

PHP $ and $$ Variables

PHP $var is a normal variable that is used to store string, integer, float, etc.

$$var is known as reference variable that is used to store $var value inside $varaible.Let us take different example to understand very easily.

Source Code

Try it now

Code Explanation: Here $fruit value will be "mango" while $$fruit can be written as $mango so $$fruit as well as $mango both values will be "orange".

Example 2

Source Code

Try it now

Code Explanation: variable $city hold value ="mumbai".

variable ${$city} hold value ="delhi" // it also declare like ${mumbai}.

variable ${$ {$city} } hold value="gorakhpur" // it act as "variable's of variable of variable" reference.