PHP Function with Optional Parameters

前端 未结 14 1195
星月不相逢
星月不相逢 2020-12-02 08:05

I\'ve written a PHP function that can accepts 10 parameters, but only 2 are required. Sometimes, I want to define the eighth parameter, but I don\'t want to type in empty st

14条回答
  •  庸人自扰
    2020-12-02 08:38

    In PHP 5.6 and later, argument lists may include the ... token to denote that the function accepts a variable number of arguments. The arguments will be passed into the given variable as an array; for example:

    Example Using ... to access variable arguments

    
    

    The above example will output:

    10
    

    Variable-length argument lists PHP Documentation

提交回复
热议问题