The $x (single dollar) is the normal variable with the name x that stores any value like string, integer, float, etc. The $$x (double dollar) is a reference variable that stores the value which can be accessed by using $ symbol before $x value.
From the given figure below, it can be easily understood that:
- $x stores the value “Geeks” of String type.
- Now reference variable $$x stores the value “for Geeks” in it of String type.
So, the value of “for geeks” can be accessed by two ways which are listed below:
- By using Reference variable directly. Example: echo $$x;
- By using the value stored at variable $x as a variable name for accessing the “for Geeks” value. Example: echo $Geeks; which will give output as “for Geeks” (without quote marks).
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 examples illustrate the use of $ and $$ in PHP:
Geeks GeeksforGeeks GeeksforGeeks
Geeks GeeksforGeeks computer science computer science
- What does '<?=' short open tag mean in PHP ?
- Where does PHP store the error log? (php5, apache, fastcgi, cpanel)
- Why PHP script does not create a directory with 777 permissions ?
- What does it mean to start a PHP function with an ampersand?
- Why does PHP 5.2+ disallow abstract static class methods ?
- How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?
- Double not (!!) operator in PHP
- What is the difference between single-quoted and double-quoted strings in PHP?
- Why does sizeof(x++) not increment x in C?
- What does the “+” (plus sign) CSS selector mean?
- What does the CSS rule “clear: both” do?
- What does main() return in C and C++?
- What does symbol tilde (~) denotes in CSS ?
- What purpose does a <script> tag serve inside of a <noscript> tag?
- Why does AngularJS include an empty option in select ?
- What does .modal('dispose') do in Bootstrap 4 ?
- Why does canvas.toDataURL() throws a security exception?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.