Change language

What does $$ (dollar dollar or double dollar) mean in PHP?

|
$X (one dollar) - it is a regular variable named x, whichstores any value, such as a string, integer, floating point, etc. $$x (double dollar) - it is a reference variable that stores a value that can be accessed by using the $symbol in front of the $x value. 
From the picture below, it is easy to see that:
  • $x stores the value of "Geeks" of type String.
  • The $$x reference variable now stores the value "For engineer" of type String.
Thus, the value "for engineer" can be obtained in two ways, which are listed below:
  • Using the link directly. Example:echo $$x;
  • Using the value stored in the $x variable as the variable name to access the value "for Geeks". Example: echo $Geeks; which will give output as "geek" (no quotes).
Examples :
Input: $x = "Geeks"; $$x = for Geeks; echo "$x"; echo "$$x;"; echo $Geeks; Output: Geeks for Geeks for Geeks Input: $x = "Rajnish"; $$x = "Noida"; echo "$x lives in". $Rajnish; Output: Rajnish lives in Noida 
Below are examples of $and $$in PHP:Example-1:

 
// Declare a variable and initialize it $x = " Geeks " ;  
// Reference variable $ $x = " GeeksforGeeks " ;  
// Display the x value echo $x . "" ;  
// Display the value $$x ($Geeks) echo $ $x . "" ;  
// Display the $Geeks value echo "$Geeks" ;  
?>
Exit:
Geeks GeeksforGeeks GeeksforGeeks 
Example 2:  
// Declare a variable and initialize it $var = " Geeks " ;  
// Reference variable ${ $var } = "GeeksforGeeks" ;  
// Using the double link variable ${${ $var }} = "computer science" ;  
// Show variable value echo $var . "" ; echo $Geeks . "" ; echo $GeeksforGeeks . "" ;  
// Double link echo ${${ $var }}. "" ;  
?>
Exit:
Geeks GeeksforGeeks computer science computer science 

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method