Variables in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dheeraja
Forum Commoner
Posts: 36
Joined: Tue Nov 09, 2010 11:03 pm

Variables in PHP

Post by dheeraja »

Hi Guys.

Right now I am working on a property site and I got there a variable $$link. So I want to know the difference between $link & $$link and also I want to know that what is the use of $_SERVER['DOCUMENT_ROOT'] variable.

Thank you.
s992
Forum Contributor
Posts: 124
Joined: Wed Oct 27, 2010 3:06 pm

Re: Variables in PHP

Post by s992 »

$$variable will declare a variable that is named as whatever $variable is. Kind of difficult to explain, let me show you:

Code: Select all

$variable = "hello";
$$variable = "this is my new variable"; // You can call this variable by using $hello, as you can see below:
echo $hello; // echoes "this is my new variable"
As for $_SERVER and other reserved variables, check out the manual!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Variables in PHP

Post by requinix »

A variable variable takes the value of a variable and treats that as the name of a variable.
Variable variables
'DOCUMENT_ROOT'
The document root directory under which the current script is executing, as defined in the server's configuration file.
$_SERVER
Post Reply