php开发(18)-include-closure-anonymous-phpstorm
* 匿名函数(anonymous functions),也叫闭包函数(closures),允许 临时创建一个没有指定名称的函数。
* 最经常用作回调函数(callback)参数的值。当然,也有其它应用的情况。
* http://php.net/manual/zh/functions.anonymous.php
* include (或 require)语句会获取指定文件中存在的所有文本/代码/标记,并复制到使用 include 语句的文件中。
* 包含文件很有用,如果您需要在网站的多张页面上引用相同的 PHP、HTML 或文本的话。
* http://www.w3school.com.cn/php/php_includes.asp
今天的练习包含4个文件,请看以下代码:(不贴图了,index.php写的打印结果,就是实际效果~)
index.php:
";
echo $jianfa(33,22); // 这里调用的是一个包含的闭包函数 , 打印结果:11
echo "
";
function callFunc($x){ // 这里调用的是一个匿名函数 , 打印结果:匿名函数
$x("匿名函数");
};
callFunc(function($str){
echo $str;
});function.inc.php:
立即学习“PHP免费学习笔记(深入)”;
";
}
function two(){
echo "222
";
}
function three(){
echo "333
";
}
function add($a, $b, $c){
return $a+$b+$c;
}
/**
* 闭包函数 php5.4 新特性 但是不常用 我们一般使用下面的匿名函数写法
* 一般用于函数回调 callback
*/
$jianfa = function ($a, $b){
return $a-$b;
};
/**
* 匿名函数
*/
// callFunc(function($str){
// echo $str;
// });test.html:
testtesttesttesttesttesttesttesttesttest
ceshi.txt:
ceshiceshiceshiceshiceshiceshi
以上就是PHP开发(18)-include-closure-anonymous-PhpStorm 的内容,更多相关内容请关注PHP中文网(www.php.cn)!











