PHP function declaration (ii)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.