You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
787 B

<?php
//定义匿名函数
$a = function(){
echo 'hello'.'<br>';
// return 'hello';
};
$a();
//查看变量内容
var_dump(($a));
//闭包=匿名函数
//函数里面的函数
function func(){
//定义局部变量
$b='world';
$innerFunc = function(){
//函数内部的函数
//调用函数func的局部变量
echo $b.'<br>';
};
//调用匿名函数
$innerFunc();
}
func();
// echo $a().'<br>';
// //匿名函数作为参数,回调函数
// $arr=[1,2,3,4];
// $ret=array_map(function ($num){
// return $num*$num;
// }, $arr);
// echo '<pre>';
// print_r($ret);
?>