开发者

PHP equivalent of Python's func(*[args])

开发者 https://www.devze.com 2023-01-26 08:59 出处:网络
In Python I can do this开发者_JAVA技巧: def f(a, b, c): print a, b, c f(*[1, 2, 3]) How do you say this in PHP?Use call_user_func_array:

In Python I can do this开发者_JAVA技巧:

def f(a, b, c):
    print a, b, c

f(*[1, 2, 3])

How do you say this in PHP?


Use call_user_func_array:

call_user_func_array('f', array(1, 2, 3));

If you wanted to call a class method, you'd use array($instance, 'f') instead of 'f' and if it was a static class function you'd use array('ClassName', 'f') or 'ClassName::f'. See the callback type docs for details about that.

0

精彩评论

暂无评论...
验证码 换一张
取 消