PHP equivalent of Python's func(*[args])
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.
精彩评论