Home »

What is the difference between $message and $$message?

Question ListCategory: PHPWhat is the difference between $message and $$message?
shah_kajal184 author asked 10 years ago
3 Answers
jeanderson295 author answered 9 years ago

The main difference between $message and $$message is that former one is a simple variable and later is a reference variable.
$message is a variable with a fixed name and it consists of a fixed value. $$messages contains the variable itself.

denielshakespeare5 author answered 9 years ago

$message is a simple variable whereas $$message is a reference variable.
Example:
$user = ‘bob’
is equivalent to
$holder = ‘user’;
$$holder = ‘bob’;

Anwser 2:
They are both variables. But $message is a variable with a fixed name. $$message is a variable who’s name is stored in $message. For example, if $message contains “var”, $$message is the same as $var.

jamessmith05 author answered 9 years ago

It is a classic example of PHP’s variable variables. take the following example.
$message = “Raghav”;$$message = “is a owner of https://sharag.wordpress.com/ “;
$message is a simple PHP variable that we are used to.

But the $$message is not a very familiar face. It creates a variable name $mizan with the value “is a moderator of PHPXperts.” assigned. break it like this${$message} => $mizanSometimes it is convenient to be able to have variable variable names.
That is, a variable name which can be set and used dynamically.

Please login or Register to Submit Answer