: This article mainly introduces the variables in PHP. if you are interested in the PHP Tutorial, you can refer to them. Overview
Variables in PHP are represented by a dollar sign followed by the variable name.
Variable names are case sensitive.
A valid variable name must start with a letter or underline followed by any number of letters, numbers, or underscores.
$ This is a special variable and cannot be assigned a value.
By default, values are always assigned. Use&
Only variables with names can reference values.
$ Foo = 25; $ bar = & $ foo; // valid value $ bar = & (24*7); // invalid; reference an expression without a name
Although you do not need to initialize variables in PHP, it is a good habit to initialize variables. Uninitialized variables have their own type default values-Boolean variables default values are FALSE, integer and floating point variables default values are zero, string variables (for example, used in echo) the default value is an empty string and an array variable. the default value is an empty array.
Predefined variables
Super global variables-Super global variables are built-in variables that are always available in all scopes $ GLOBALS-reference all variables available in the global scope $ _ SERVER-SERVER and execution environment information $ _ GET -http get variable $ _ POST-http post variable $ _ FILES-HTTP file Upload variable $ _ REQUEST-HTTP Request variable $ _ SESSION-Session variable $ _ ENV-environment variable $ _ COOKIE-HTTP Cookies $ php_errormsg-previous error message $ HTTP_RAW_POST_DATA-native POST data $ http_response_header-HTTP response header $ argc-number of parameters passed to the script $ argv-parameters passed to the script array
Many predefined variables in PHP are "super Global", which means they are available in all scopes of a script. You can access functions or methods without performing global $ variable.
Variable scope
The global variable is automatically invalid in the function.
Global variables in PHP must be declaredglobal
The second way to access variables globally is to use a special PHP custom$GLOBALS
Array
Static variables
Another important feature of variable range is static variable ). Static variables only exist in local function domains, but their values are not lost when the program runs out of this scope.
Variable
Variable names can be dynamically set and used.
$Bar = "a";$Foo = "Bar";$World = "Foo";$Hello = "World";$a = "Hello";$a; //Returns Hello$$a; //Returns World$$$a; //Returns Foo$$$$a; //Returns Bar$$$$$a; //Returns a
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above describes the variables in PHP, including the relevant content, and hope to help those who are interested in the PHP Tutorial.