Tutorialsplane

PHP $ Vs $$


PHP $ Vs $$ :– If $a = ‘b’ then $$a is $b.

$variable is a normal variable $$variable takes the value of a variable and treats that as the name of a variable

Assuming $a = “foo”, $$a will be same as $foo

In PHP each variable starts with an $.

So for example you have the variable $a = ‘var’;

So $$a == $var

This new variable will have the “content” of the other variable as name.

Example

<?php $a = "b";
$b="hello";
echo $$a;
??>

PHP Tutorial