|
A variable might be defined as a storage cell created to introduce or to assign any value or fact. During the execution of the script the value of the variable can "change" (cost the redundancy) both of type and of value. In PHP (as in JavaScript) it is not necessary to declare the variable since simply preferring the character $ to the name of the variable we are indicating that it is a variable.
Another fact that it is necessary to emphasize at the time of programming in PHP and the declaration of variables is that PHP is a language "MARRY SENSITIVE" that is to say that differs between capital letters and small letters and due to this reason it would not be the same $miVariable=valor; that $MiVaRiABle=valor; since PHP would interpret it as two completely different variables.
The types of possible information that sound can store variable the following ones:
| Integer |
Positive and negative entire numbers |
| Double |
Decimal numbers or of floating comma |
| String |
Chains of text | |
| Boolean |
Values True or False |
| Array |
Special type of collection of values |
| Object |
Special type of complex fact |
In later chapters we will give capacity to the last two types of information (array and object) that here have been explained nor commented scarcely.
To turn types
PHP is a language that realizes the types conversion according to the operandos and the operator. Thus if we try to add the chain '10' and the number 20 the action that it would realize would be to turn the first variable to numerical and thus it might add up 10+20=30.
Apart from the fact that PHP in some cases realizes the conversion there exist two special functions of the proper language which allow us to know the type of variable that we are using and also they can turn the type of variable:
gettype () It Receives the type of variable that is
settype ($variable, 'variable type') There Transforms the type of variable of a current way to the way that we introduce him.
Variables typical of PHP
| argv |
Array of arguments spent in the execution of the script. |
| $_SERVER ['argc'] |
Number of parameters gone on to the script in his execution. |
| $_SERVER ['PHP_SELF'] |
Name of the script who is executed |
| $_COOKIE |
Associative Array of pairs (key, value) spent across cookies |
| $_GET |
Associative Array of pairs (key, value) spent across GET |
| $_POST |
Associative Array of pairs (key, value) spent across POST |
| $_FILES |
Associative Array that contains information of the files received by means of POST |
| $_ENV |
Associative Array of pairs (key, value) of the environment |
| $_SERVER |
Associative Array of pairs (key, value) of the servant |
| $_SESSION |
Associative Array of pairs (key, value) of meeting |
Constants
There are values that they are going to support constants along the execution of the script and that possibly let's want to use along the script a big number of times. For it we use the following syntax:
it defines ("name of the constant", value);
|