php中是否有类似objective c nil终止的东西


Is there something like objective c nil terminate in php?

在Objective-C中,我可以有这样一个方法:

+ (id)arrayWithObjects:(id)firstObj, ...;

我可以传递任意多的对象,直到我在最后一个参数中传递一个nil

在php中,我可以有这个能力也…?谢谢你…

在PHP中,你可以做同样的事情——除了你不需要将null作为最后一个参数:只需要将你想要的参数传递给你的方法。

然后,在此方法中,使用诸如 func_get_args() 之类的函数来访问它接收到的参数。

我在Google上搜索"PHP变量参数",发现:

  • http://php.net/manual/en/function.func-num-args.php
  • http://php.net/manual/en/functions.arguments.php
  • http://php.net/manual/en/function.func-get-args.php
  • http://www.bestcodingpractices.com/php_function_with_variable_arguments - 9. - html

专业提示:Google是免费的