How do you create optional arguments in php?

后端 未结 6 1696
耶瑟儿~
耶瑟儿~ 2020-11-27 02:54

In the PHP manual, to show the syntax for functions with optional parameters, they use brackets around each set of dependent optional parameter. For example, for the date()

6条回答
  •  面向向阳花
    2020-11-27 03:47

    Some notes that I also found useful:

    • Keep your default values on the right side.

      function whatever($var1, $var2, $var3="constant", $var4="another")
      
    • The default value of the argument must be a constant expression. It can't be a variable or a function call.

提交回复
热议问题