What Are The Variables In PHP

Publicat de King Of The East | 09:28

Imagine a chimney, you have apples, pears, oranges. You're much easier to share their careers and their children. Now think what would you do if not who should basket and all the fruit by hand. You would be much harder. So it is with variables in PHP.
variable is like a basket that you can specifically define and then one to keep a specific value (number, string, etc..). Let's take an example to understand better.
In previous lesson you've explained how to do a simple PHP page. Then you see what is the echo function.
Eg If you add two numbers, you'll get: echo 1 +3, will certainly result display 4. But this gathering is useful only to those who want to assemble a 3. At this point, variables come into play.
Variables allow us to gather more such numbers without caring directly in data values.
How to define a variable in PHP?
Simple. A variable consists of your chosen name, preceded by the sign for the dollar ($). This may include letters, numbers, underscore (_) but can not contain spaces. Always a variable name must begin with a letter or underscore character. Like this:
$ Variable
$ Variabila_noua
$ _1variabila_mare
$ Altavariabila2
$ Variabila_alta2
As a tip: try to give a name easy to remember as your variables. In time you will feel easy to work with, but if you look over the same script from 2.3 weeks after you've done, in case you have not used variables understandable, you'll get a lot of work to figure what each account.
Global variables and superglobal
If before I had the appointment rules of the variables, you should know that there are rules regarding the availability of the variable concerned. What does that mean? The fact that PHP has several predefined variables, called variable superglobal. These variables are always present, their values ​​are available for all your scripts.
And the story becomes complicated, you have to know that ... each of the variables superglobal are actually vectors containing other variables:
$ _GET - Contains all variables that are sent through the GET method script
$ _POST - Contains all variables that are submitted through POST method script
$ _COOKIE - Contains all variables that are transmitted through cookies script
$ _FILES - Contains all variables which are submitted script when I want to upload a file server
$ _SERVER - Contains information such as headers, paths to files, physical location of the scripts
$ _ENV - Contains all variables that are in the working environment of the server and are accessible script
$ _REQUEST - Contains all variables which shall be transmitted to the script by POST or GET method
$ _SESSION - Contains all variables that are recorded in a user session
I hope not too confusing. So far it's good if you know what is a variable, how to define variables that are acceptable and what are the variables superglobal. So much for today. On future.