| Home | About | Downloads | Features | Demo | FAQ | Forum | Screenshots | PHP Tutorials | |
<< PHP Syntax |
PHP Tutorials |
PHP Comments >>
PHP VariablesWell, if you've haven't taken Algebra, or done any other programming before variables are basically what their name suggests. A variable can contain data, that can vary in values. You can store things like integers, strings, booleans (true or false) and so on and so forth. Variables are always set using this simple code:
$variable = value; $another_variable = another_value; Choosing a Variable Name
Choosing a variable name is not as hard as you think (well you probably don't think it's hard, I just
thought it would be cool to say that). There are some rules though, that must be followed or the code
just won't work. First of all, let's look at a little piece of text I took from the PHP.net website: Different Data TypesUnlike most other programming languages, PHP does not require that you initialize your variables. This basically means you don't have to define a big list of all your variables before you get started. As well the PHP engine automatically chooses the best data type it should be (int, bool, double, etc.). Here is an example of some variables being set:
<?php $integer = 1; $string = 'Hello'; $boolean = false; ?> These are all valid variables. The PHP engine will decide the first one to be an integer (due to lack of quotes, and it's an integer), the second a string (because of the quotes) and the last boolean (because of no quotes, and it's false or true). Predefined VariablesAhhh the horror of having to remember which variables are already defined by the PHP engine! Just wait until you start writing functions and have to remember the function names :S Anyway, enough with functions we are talking about variables... yes! Predefined variables exist for the better-ment of the PHP community. Some predefined variables are not in use anymore, but may still be in existance on some servers. They are the ones that are in the HTTP_*_VARS format. Here is a list for you:
* $_REQUEST cannot be trusted, and I suggest you never use it - ever. |
|
| © Douglas Rennehan 2007 - 2008 | Terms of Service | Privacy Policy | Valid XHTML 1.0 | Valid CSS | |