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

yipeiwu_com6年前PHP代码库

call_user_func_array

call_user_func_array — 调用回调函数,并把一个数组参数作为回调函数的参数

mixed call_user_func_array ( callable $callback , array $param_arr )

把第一个参数作为回调函数(callback)调用,把参数数组作(param_arr)为回调函数的的参数传入。

例子:

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

输出结果:

foobar got one and two

foo::bar got three and four

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家学习或者使用PHP能有所帮助,如果有疑问大家可以留言交流。

相关文章

PHP无敌近乎加密方式!

因为本人对sql注入比较喜欢 前前后后 检测过不少网站 aspphpjsp 发现基本都是用md5加密算法 都说 MD5 不可逆 无法破 对 MD5是无法逆 可是可以暴力破 只需要把常用的...

php和C#的yield迭代器实现方法对比分析

本文实例讲述了php和C#的yield迭代器实现方法对比。分享给大家供大家参考,具体如下: yield关键字是用来方便实现迭代器的,免去了手工写迭代器的繁琐。迭代器常被用来实现协程,所以...

smarty section简介与用法分析

基本原形为: {section name = name loop = $varName[, start = $start, step = $step, max = $max, show...

php一个文件搞定微信jssdk配置

php一个文件搞定微信jssdk配置: 包括缓存,包括https通讯,获取微信access_token,签名什么的都有。但是防范性编程做得比较少,商业用的话,需要完善下代码。 使用姿势...

将FCKeditor导入PHP+SMARTY的实现方法

本文实例讲述了将FCKeditor导入PHP+SMARTY的实现方法。分享给大家供大家参考。具体分析如下: 提取Fckeditor时,采用如下,PHP用$_POST['p_info']得...