0

As we know that $ is used to declaring the variable in PHP, but most of the programmer uses $$ to pass the value of one variable into another. and we can say that $$ used when we want to use a dynamic variable name not a fixed variable name.

What Is The Difference Between $ And $$ in PHP?

Let take an example of $ and $$ to learn in detail

<?php
$var = "Hello";
$$var = "World";
echo $var;
echo "<br>";
echo $$var;
echo "<br>";
echo $Hello;

Output

Hello
World
World

Explanation :

$var = “Hello”;

$$var = “World”;

we can say that  $Hello = “World” because we have delare $var=”Hello” and when we trying to echo $Hello then output will be World

 

Changed status to publish