PHP相当于Python的函数(*[args])

wes*_*wes 4 php python args

在Python中我可以这样做:

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

f(*[1, 2, 3])
Run Code Online (Sandbox Code Playgroud)

用PHP怎么说?

Thi*_*ter 9

使用call_user_func_array:

call_user_func_array('f', array(1, 2, 3));
Run Code Online (Sandbox Code Playgroud)

如果你想调用一个类方法,你可以使用array($instance, 'f')而不是,'f'如果它是你使用的静态类函数array('ClassName', 'f')'ClassName::f'.有关详细信息,请参阅回调类型文档.

  • 我的眼睛,护目镜,他们什么都不做!提醒我为什么我现在可以用Python编写代码... (3认同)