《PHP實例:PHP中call_user_func_array回調函數的用法示例》要點:
本文介紹了PHP實例:PHP中call_user_func_array回調函數的用法示例,希望對您有用。如果有疑問,可以聯系我們。
call_user_func_arrayPHP學習
call_user_func_array
― 調用回調函數,并把一個數組參數作為回調函數的參數PHP學習
mixed call_user_func_array ( callable $callback , array $param_arr )
把第一個參數作為回調函數(callback)調用,把參數數組作(param_arr)為回調函數的的參數傳入.PHP學習
例子: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")); dump("<br/>"); // Call the $foo->bar() method with 2 arguments $foo = new foo; call_user_func_array(array($foo, "bar"), array("three", "four"));
輸出結果:PHP學習
foobar got one and two foo::bar got three and four
總結PHP學習
以上就是這篇文章的全部內容了,希望本文的內容對大家學習或者使用PHP能有所幫助,如果有疑問大家可以留言交流.
PHP學習
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/2582.html