Home > Backend Development > PHP Tutorial > Common functions in PHP: custom functions, callback functions, recursive functions, etc.

Common functions in PHP: custom functions, callback functions, recursive functions, etc.

WBOY
Release: 2016-07-25 08:51:22
Original
1180 people have browsed it
What are the commonly used functions in PHP, some examples of PHP custom functions, callback functions, variable functions and recursive functions, as well as the usage of PHP global variables, local variables and static functions, etc.

php function language structure: if() for() while() switch() echo() print() array() list() foreach() isset() unset() empty() exit() die() include() require()

Custom function:

function fun(){}

1. Call function fun()

"."$i*$j=".($i*$j)." "; } echo "
"; } echo "
"; } jiutb(9,"#cccccc"); jiutb(10,"red"); ?>

Default parameters:

function jiutb($num=9,$color="black"){ }

2. Variable parameters

3. The sum of infinite parameters:

4. Variable function

function fun(){} $a="fun"; $a(2,3,4,5);

Variable scope: 1.Global variables Variables outside the function

2. Local variables Variables inside the function

The glocal keyword can turn local variables into global variables after modification

Quote parameters: 1. The internal and external functions point to the same address.

Callback function: It is a type of parameter. If the parameter of a function is the name of another function, then this parameter is called a callback function.

Static variables When the same function is called multiple times, static variables can be kept track of.

//When calling the program, count how many times this function is called. "; } show(); show(); ?>

Static variable method:

"; } show(); show(); show(); ?>

File contains: 1.include() contains an error and the script continues to execute 2.require() If there is an error, the script will terminate immediately

Recursive function: Call this function inside the function 1.Sum:

//recursive function $num=100; for($i=1;$i Function calling order show(); function show(){} show();

6.php execution sequence 1. Load the page 2. Grammar detection (1. Grammar detection 2. Loading function) 3. Execute the script



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template