Home >Backend Development >PHP Tutorial >How to Create Optional Arguments in PHP?
Creating Optional Arguments in PHP
In PHP, you may encounter functions with optional parameters where brackets are used to group dependent optional parameters in the manual syntax. For example, in the date() function, $timestamp is optional and defaults to time().
To create similar optional parameters in custom PHP functions, simply utilize an equals (=) sign within the parameter definition.
<code class="php">function dosomething($var1, $var2, $var3 = 'somevalue'){ // Function implementation... }</code>
In this example, $var3 has the default value of 'somevalue'.
The above is the detailed content of How to Create Optional Arguments in PHP?. For more information, please follow other related articles on the PHP Chinese website!