【问题标题】:ajax response inside a function by ob cleanob clean 函数内的ajax响应
【发布时间】:2017-03-27 09:04:35
【问题描述】:

我正在寻找一种通过函数调用函数并在函数中执行其内容的方法,例如:

function response($execute){
    ob_clean();
    $execute();
    die();
}

所以当我打电话时,我想给它一个过程作为参数,比如:

response(echo("hi"));

【问题讨论】:

  • 你期待hi函数被调用吗?
  • @SahilGulati 我想得到回声函数作为参数
  • 您只希望 echo 函数作为参数还是任何 anonymous 函数或闭包?
  • echo 函数就是一个例子,我也想要匿名函数

标签: php function arguments


【解决方案1】:

PHP 使用匿名函数。

PHP code demo

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");

【讨论】:

  • 谢谢大师!
  • 是否有检测到 $execute 是 response() 内部的函数或变量?
猜你喜欢
  • 2011-02-25
  • 2015-08-10
  • 2011-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多