Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic Question regarding PHP

Status
Not open for further replies.

nawrioj

Programmer
Feb 14, 2005
22
US
What is the difference between $message and $$message ? anybody know?

 
You are dealing with variables, and variable variables.

All variable names in PHP start with $.

Example:

Code:
<?

$name = 'scorpion';
echo $name; will display 'scorpion'

?>

Variable variables are just what they sound like. They are variables, with a name that's also changeable. So...
Code:
$name = "john";
$$name = "ss";

echo $john; // will display 'ss';

It might be hard to understand, but it makes perfect sense.
Take my code again:
$name = "john";
$$name = "ss";

In the second line, the first $ is to declare the variable, and its replacing "$name" with its value, which is john. Therefore, its declaring a variable named "john", and placing "ss" as its value..

They're very useful, but I don't use them that often. When you need to use them, you'll know.
 
$message is a variable
$$message is a reference to a variable variable...

so
Code:
$message = "hello";
echo $message ; gives "Hello"

echo $$message; //gives nothing

$hello = "variable variable";
echo $$message; //gives "variable variable"
[/oode]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top