PHPBuilder - The ABC's of PHP Part 4 - How Variable Am I? Page 4

RSS Twitter

The ABC's of PHP Part 4 - How Variable Am I? - Page 4

by: PHP Builder Staff
April 1, 2009

Some Variables are Special.
Some variables have a special purpose in PHP, that is they are reserved to hold specific values and are created by PHP itself, also built in function names cannot be used as variable names.
The PHP manual has a full list of these variables, but some of the more important ones are the array collections $_POST , $_GET , $_REQUEST, $_SERVER and $_ENV, We'll cover arrays in more detail at a later date, but for now if you look at the phpinfo script that we created in the second article in the series, you'll see near the bottom that there is a list of the elements in the $_SERVER and $_ENV variables.
To get the value of these variables simply use the variable name followed by the item name quoted in square brackets, eg:
The $_POST, $_GET and $_REQUEST variables are populated by values passed to your script. We'll look at $_POST in the article on arrays, but for now if you try running your script using http://localhost/myscript.php?myvar=hello&age=21, you'll find that the variables $_GET["myvar"] and $_GET["age"] will hold the values "hello" and 21 respectively.
In this episode of the ABC's of PHP we looked at the basics of using variable data in your script, and how they can be used, over the next three parts we'll look at the different types of data in more detail starting in part 5 with strings and text. Then in part 6 we'll cover maths and numbers.
In the mean time the variables page in the PHP manual is worth a read, particularly the page on the predefined variables, as there are a couple of warnings in there about using globals, and the register-globals depreciated functions.
The PHP variables page can be found at
Until next timeĀ…
Happy scripting

« Previous Page

Comment and Contribute

Your comment has been submitted and is pending approval.




(Maximum characters: 1200). You have characters left.