Follow Baidu learn php[5] special form function in function Chapter 2-php

Source: Internet
Author: User
Tags learn php

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

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.