call_user_func_array调用回调函数

142次阅读
没有评论

http://php.net/manual/zh/function.call-user-func-array.php

感觉用这种方法来调用 函数 或者 对象的方法 很有逼格啊

call_user_func_array — 调用回调函数,并把一个数组参数作为回调函数的参数

<?php

function foobar($arg, $arg2) {echo __FUNCTION__, "got $arg and $arg2 <br>";}

call_user_func_array("foobar", array("one", "two"));

输出结果: foobar got one and two

<?php

class foo {function bar($arg, $arg2) {echo __METHOD__, "got $arg and $arg2<br>";}
}

// Call the $foo->bar() method with 2 arguments
$foo = new foo;

call_user_func_array(array($foo, "bar"), array("three", "four"));

输出结果: foo::bar got three and four

正文完
有偿技术支持加微信
post-qrcode
 
评论(没有评论)
验证码