Stupid bird php (5) function declaration and use

Source: Internet
Author: User
Stupid bird php (5) function declaration and use 1. function declaration & lt ;? Php *** function name (parameter 1, parameter 2 ....) {* function body; * return value; *} * $ sumsum (3,4); echo $ sum; functionsum ($ x, $ y) {$ sum0; $ sum $ x * $ x description and use of the stupid php (5) function

1. function declaration

 

2. variable range

Local variable: the variable declared in the function is a local variable and can only be used within the function..
Global variable: the variable declared outside the function is a global variable. it can be used after the variable declaration until the end of the script, including in the function and {}..

2.1 Knowledge Point: PHP variables cannot be declared or used

 ';} Demo ($ a); echo $ a; // Result: 20, 10 // The PHP variable cannot be identified. $ a is declared or used?>
2.2 Knowledge Point: The global keyword must be used to use global variables in a function. the variables after global declaration are global variables.

 ";}function test() {global $a;$a += 5;echo $a . "test 
";}echo $a . " ----
"; // 10 ----demo(); // 20 demo echo $a . " !!!!
"; // 20 !!!!demo(); // 30 demo echo $a . " @@@@
"; // 30 @@@@test(); // 35 test echo $a . " ####
"; // 35 ####?>

Static variables: they can only be declared in the function (class) and cannot be declared globally. they must be modified with the static keyword before the variable..

2.3 Knowledge Point: static variables are stored in static code blocks. their values can be shared among multiple calls of a function, but are declared to the memory only when a function is called for the first time.

It will not be declared and used directly (similar to Java) in future calls ).

 ";   }  test(); // 1  test(); // 2  test(); // 3?>

3. variable functions

In fact, this is similar to JS. for example, if $ var = hello is defined, the next time you use $ var (), you will find the function hello () with the same name as the variable value ()

 "; // 91?>

4. system functions

4.1 General functions
Bool copy (string source, string dest)

4.2 With mixed. mixed indicates that data of any type can be uploaded.
Bool chown (string filename, mixed user)

4.3 A function with an & parameter indicates that a value is referenced. a value cannot be passed but only one variable can be passed. then, the function changes the value of the variable,

When we use this variable, the value also changes (and the reference in Java is the same)

Bool arsort (array & array [, int sort_flags])
 
4.4 default function: a function with [], indicating that this parameter is optional. if you pass a value, use the value you pass. If no value is passed, use the default value.
Bool arsort (array & array [, int sort_flags])
 ";}demo(8,9);?>
4.5 parameter functions...
Int array_unshift (array & array, mixed var [, mixed...])

 

4.6 The callback function has callback, that is, when calling this function, we need to pass in a function (function name, function name string)
Array array_filter (array input [, callback])

  2 [3] => 4 [5] => 6 [7] => 8 ) ?>


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.