Differences between Simple Variables and Variable Variables

Q

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

✍: FYIcenter

A

$message is a simple variable with a fixed name which is called "message".

$$message is a variable variable with a variable name which is stored in another variable called $message.

If $message contains "user", $$message is the same as $user. For example, this code will produce "bob" and "bob":

<?php
$holder = 'user';
$$holder = 'bob';
echo $$holder;
echo $user;
?>

2007-02-27, 4991👍, 0💬