相关疑难解决方法(0)

PHP call_user_func与仅调用函数

我确信对此有一个非常简单的解释.这有什么区别:

function barber($type){
    echo "You wanted a $type haircut, no problem\n";
}
call_user_func('barber', "mushroom");
call_user_func('barber', "shave");
Run Code Online (Sandbox Code Playgroud)

......这个(有什么好处?):

function barber($type){
    echo "You wanted a $type haircut, no problem\n";
}
barber('mushroom');
barber('shave');
Run Code Online (Sandbox Code Playgroud)

php function

86
推荐指数
5
解决办法
5万
查看次数

为什么在常规调用函数时更喜欢call_user_func_array?

function foobar($arg, $arg2) {
    echo __FUNCTION__, " got $arg and $arg2\n";
}
foobar('one','two'); // OUTPUTS : foobar got one and two 

call_user_func_array("foobar", array("one", "two")); // // OUTPUTS : foobar got one and two 
Run Code Online (Sandbox Code Playgroud)

我可以看到常规call_user_func_array方法和 方法都输出相同,那么为什么要选择它呢?

在哪种情况下,常规调用方法会失败,但call_user_func_array不会?

我能得到这样的例子吗?

谢谢

php function callback

46
推荐指数
5
解决办法
3万
查看次数

标签 统计

function ×2

php ×2

callback ×1