PHP Single dollar variable $x and Double dollar variable $$x?

In this blog, We are going to learn the difference between $x and $$x?

PHP $x and $$x Variables

$x (single dollar)

The $x (single dollar) is the normal variable with the name x that stores any value like string, integer, or float.

$$x (double dollar)

The $$x is a reference variable that stores the value which can be accessed by using $ symbol before $x value.

let’s understand with an example:

<?php  
$x = "hello";  
$$x = 500;  
echo $x."<br>";  
echo $$x."<br>";  
echo $hello;  
?>

we have printed the values $x, $$x, and $hello.

Output:

hello
500
500

In this example, we have assigned a value to the variable x as hello. Value of reference variable $$x is assigned as 500.

I hope that you found this Blog helpful. If you’ve any queries, please leave comments in the comment section.

Thanks for following and reading this blog.

expoundsofttechsolution

learn the difference between $x and $$x