Home  >  Article  >  Backend Development  >  解析php中call_user_func_array的作用_php技巧

解析php中call_user_func_array的作用_php技巧

WBOY
WBOYOriginal
2016-05-17 09:02:561095browse

一、直接调用方法

复制代码 代码如下:

function test($a, $b)
{
echo '测试一:'.$a.$b;
}
//调用test方法,array("asp", 'php')对应相应的参数
call_user_func_array('test', array("asp", 'php'));

二、通过类调用类中的方法

复制代码 代码如下:

class test2{
function phpSay($a, $b)
{
echo '测试二:'.$a.$b;
}
}
$o = new test2();
//相当于:$o->phpSay('php','你好');
call_user_func_array(array(&$o, 'phpSay'), array('php','你好'));
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn