#native_company# #native_desc#
#native_cta#

The ABC’s of PHP Part 4 – How Variable Am I? Page 4

By PHP Builder Staff
on 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:

print $_SERVER["SERVER_ADDR"];
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.
Summary
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
http://www.phpbuilder.com/manual/language.variables.php.
Until next time??
Happy scripting
Shawty

1
|
2
|
3
|
4