call_user_func_array()
call_user_func_array(callable $callback, array $param_arr) 调用回调函数,并把一个数组参数作为回调函数的参数。这个回调函数可以为函数或类方法。
参数:
callback 被调用的回调函数。
param_arr 要被传入回调函数的数组,这个数组得是索引数组。
举例:
<?php
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"));
// 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
参考:http://php.net/manual/zh/function.call-user-func-array.php

浙公网安备 33010602011771号