我正在寻找一种方式来通过一个函数调用的函数,得到的功能等它的内容执行:Ajax响应
function response($execute){
ob_clean();
$execute();
die();
}
所以,当我打电话,我想给它一个参数的过程,如:
response(echo("hi"));
我正在寻找一种方式来通过一个函数调用的函数,得到的功能等它的内容执行:Ajax响应
function response($execute){
ob_clean();
$execute();
die();
}
所以,当我打电话,我想给它一个参数的过程,如:
response(echo("hi"));
PHP使用匿名函数。
function response($execute)
{
if(is_callable($execute))
{
$execute("some-value");
}
else
{
echo "Not a function";
}
}
response(function($someVariable){
echo "Hi i am in anonymous function with 1st argument ".$someVariable;
});
response("Hi");
谢谢高手! –
@AmirForsatiQ。欢迎..... :) –
有无论如何检测到$ execute是函数还是变量里面的response()? –
你期待'hi'功能应该叫什么名字? –
@SahilGulati我想获得回声函数作为参数 –
你是否只想要回声函数作为参数或任何'匿名'函数或闭包? –