源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

PHP中call_user_func_array回调函数的用法示例

  • 时间:2022-08-10 14:27 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:PHP中call_user_func_array回调函数的用法示例
[b]call_user_func_array[/b] [code]call_user_func_array[/code] — 调用回调函数,并把一个数组参数作为回调函数的参数
mixed call_user_func_array ( callable $callback , array $param_arr )
把第一个参数作为回调函数(callback)调用,把参数数组作(param_arr)为回调函数的的参数传入。 [b]例子:[/b]
function foobar($arg, $arg2) {
  echo __FUNCTION__, " got $arg and $arg2\n";
}
class foo {
  function bar($arg, $arg2) {
    echo __METHOD__, " got $arg and $arg2\n";
  }
}


// Call the foobar() function with 2 arguments
call_user_func_array("foobar", array("one", "two"));
dump("<br/>");
// Call the $foo->bar() method with 2 arguments
$foo = new foo;
call_user_func_array(array($foo, "bar"), array("three", "four"));
[b]输出结果:[/b]
foobar got one and two

foo::bar got three and four
[b]总结[/b] 以上就是这篇文章的全部内容了,希望本文的内容对大家学习或者使用PHP能有所帮助,如果有疑问大家可以留言交流。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部