Directory......................................................
.00x1 variable functions
.00x2 callback function
.00x3
.
.................................................... .......
Use of 00x1 variable functions
In PHP, if you assign a "function name" to a variable of type string. If you use parentheses when calling this variable, PHP will parse it as a function. This is called a mutable function.
NOTE: mutable functions may not be used for echo,print,unset (), Isset (), Empty (), Include,require, and similar language constructs, which need to be implemented in their own package.
<? $a = ' md5 '; Echo $a (' Hello World '); Echo "<br/>"; Echo MD5 (' Hello World '?>/* The output effect is as follows: 5EB63BBBE01EEED093CB22BB8F5ACDC35EB63BBBE01EEED093CB22BB8F5ACDC3* /
Use of the 00x2 callback function
When calling another function 2 in a function 1, a function 2 is passed in as a parameter and is used in function 1.
Single function parameter case:
<?PHPfunctionPlay () {Echo"Playing...<br/>";}functionStudy () {Echo"Studying...<br/>";}functionSing () {Echo"Singing...<br/>";}functionDowhat ($x){ Echo"She"; Echo $x();} Dowhat (' Play '); ?>/*the output results are as follows: she playing ...*/
Multiple function parameter cases:
<?PHPfunctionStudy$username){ Echo $username. "Studying...<br/>";}functionPlay$username){ Echo $username. "Playing...<br/>";}functionEat$username){ Echo $username. "Eating...<br/>";}functionDowhat ($functionName,$param){#can be understood as eat is the $functionname parameter, $param is the $username parameter in the Eat function. $functionName($param);} Dowhat (' Play ', ' look Daniel '); ?>
Use the callback function to implement the add and subtract operation:
<?PHP/*using callback functions to implement add and subtract operations*/functionJiafa ($x,$y){ return $x+$y;}functionJIANFA ($x,$y){ return $x-$y;}functionJiajian ($suanfa,$q,$w){ return $suanfa($q,$w);}EchoJiajian (' Jianfa ', ' 2 ', ' 3 '); ?>
00x3 use of anonymous functions
00x4 use of functions with variable parameter forms
The use of 00x5 recursive functions
Follow Baidu learn php[5] special form function in function Chapter 2-php