View Single Post
Old 06-05-2009, 01:02 PM   #2 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

First off, welcome to the community !

There are actually two types of these predominantly used to pass variables to various documents. You've probably seen them when browsing websites. Typically, but certainly not always, they consist of key/value pairs.

Example:

Code:
http://www.example.com/index.php?var1=I Love&var2=TalkPHP
Those are what we call GET variables. The other type are POST variables and they are sent with the HTTP request. They are in the same format as the GET variable (In key/value style) but are hidden away from the user as they are not present in the URL.

What I mean by key/value pairs is that the first item is the key, and the second being its value. Take a look at the following as shown in our example:

Code:
var2=TalkPHP
In there var2 would be the key, and TalkPHP is the value for that key.

Now that we know that, to answer your question. Using our example again we would extract the value TalkPHP from the URL using $_GET['var2'];. If you're currently knowledgeable about arrays, then $_GET is simply one big array that contains all the variables passed to it via GET (Not POST, for POST we have $_POST).

In your example, the GET variable a can be set to 1 or 2, or not at all. That is why there is an if statement checking its value.

To tie this up, using our above example of:

Code:
http://www.example.com/index.php?var1=I Love&var2=TalkPHP
We could print "I Love TalkPHP" by referencing the 2 keys (var1 and var2):

php Code:
/* GET: var1=I Love&var2=TalkPHP */
echo $_GET['var1'] . ' ' . $_GET['var2']
/* Prints: I Love TalkPHP

I hope I have explained it well for you Please let me know if not.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
dodgeqwe (06-05-2009)