Home  >  Article  >  Backend Development  >  Detailed explanation of anonymous functions and callback functions in php

Detailed explanation of anonymous functions and callback functions in php

王林
王林forward
2020-01-14 17:50:382798browse

Detailed explanation of anonymous functions and callback functions in php

Anonymous function is a function without a name. You can assign the function to a variable and then call it.

The callback function refers to a function that is used as a parameter value for another function.

(Free learning video tutorial sharing: php video tutorial)

Code examples are as follows:

//匿名函数 没名称的函数
$a=function (){
echo "www.php.cn";
}
$a();
//回调函数 函数名作为参数供其他函数使用
call_user_func("函数名",参数)
function $a(){
echo "www.php.cn";
}
call_user_func("a",参数)
//也相当于可以传入一个匿名函数进去使用

Recommended related article tutorials: php tutorial

The above is the detailed content of Detailed explanation of anonymous functions and callback functions in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete