Example of call_user_func_array callback function in PHP: calluserfuncarray
Call_user_func_array
call_user_func_array-Call the callback function and use an array parameter as the callback function parameter.
mixed call_user_func_array ( callable $callback , array $param_arr )
Call the first parameter as the callback function, and pass in the parameter array as the parameter (param_arr) of the callback function.
Example:
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 argumentscall_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"));
Output result:
foobar got one and twofoo::bar got three and four
Summary
The above is all the content of this article. I hope the content of this article will be helpful for everyone to learn or use PHP. If you have any questions, please leave a message.