The range of variables in PHP
1. Local variables: variables declared in a function are local variables and can only be used inside their own functions.
2. Global variables: Out-of-function declaration, after the variable declaration, until the end of the entire script can be used, including in the function and {} can be used
3.PHP is not a variable, is the declaration or the use of
4. Use global variables in PHP to include this global variable in the function through the global keyword to be used, the global variable is the time after the declaration.
5. The parameter is a local variable, which can be called to assign a value.
Static Variables for PHP
A static variable can only be declared in a function (in a class) and cannot be used in a global declaration before a variable;
Function: A variable can be used in multiple invocations of the same function.
1. Static variables are saved in a static code segment
2. A function is shared between multiple invocations, but is declared to memory only the first time the function is called, and then later invoked, no longer declared, but directly using the
function Test () {
static $a = 0;
$a + +;
echo $a. " <br> ";
}
Test ();
Test ();
Test ();
Test ();
Test ();
Test ();
Test ();
Test ();
Test ();
Test ();
Test ();
Test ();
Variable function: If a variable is followed by parentheses $var=hello $var (), it will look for a function hello () with the same name as the variable value;
function one ($a, $b) {
return $a + $b;
}
function ($a, $b) {
Return $a * $a + $b * $b;
}
Function three ($a, $b) {
return $a * $a * $a + $b * $b * $b;
}
$var =one;
$var = "both";
$var =three;
echo "Result:". $var (3, 4). " <br> ";
1. function--------Decide whether to use this function
2. The parameters of the function--------determine how the function is called---have several arguments, what type of value to pass
3. The return value of the function-----called to handle this function
PHP to more than 2000 functions, all belong to the system functions, can be used directly by name.
Be sure to use the system function first, if the system function does not have the function you want, then go to define the function yourself
1. General functions
BOOL Copy (string source, String dest)
2. With mixed, mixed means that any type of data can be transmitted
BOOL Chown (string filename, mixed user)
3. A function with & parameters, indicating the reference assignment, this parameter can not pass the value, can only pass a variable, and then the function will change the value of the variable, we use this variable, the value is also changed
BOOL Arsort (array &array [, int sort_flags])
PHP function declaration (ii)