VOOZH about

URL: https://www.geeksforgeeks.org/php/difference-between-var-and-var-in-php/

⇱ Difference between $var and $$var in PHP - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Difference between $var and $$var in PHP

Last Updated : 23 Jul, 2025

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.

$var:

Syntax:

$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 $.

 

Output
hello Geeks<br/>1<br/>34<br/>

$$var: $$var stores the value of $variable inside it.

Syntax:

$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.


Output
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.

Comment