Arguments that do not stop the function from working even though there is nothing passed to it are known as optional arguments. Arguments whose presence is completely optional, their value will be taken by the program if provided. But if no value is given for a certain argument, the program will not halt. These arguments are given rise by usually providing the function with a default value for the parameter. Now, if the function is given with the value of the argument during the call, the given arguments overwrite the default one and the program continues normally. But if the call doesn’t provide the function with any value, the program continues normally with the default ones.
The idea here is to create such optional arguments within are program. This will as mentioned will be carried out using the default value.
Flow chart: Although the concept is pretty straight-forward but here is a flow chart to understand better.
Below examples illustrate the optional arguments in PHP.
Travelling to Sweden. Traveling to Australia. Traveling to Tokyo.
Example 2: In this example it confirms that the timer is set.
Timer set for 0 : 0 : 0. Timer set for 10 : 30 : 0. Timer set for 0 : 20 : 40.
- How to create optional arguments for a SASS mixin?
- CSS | optional Selector
- How to describe “object” arguments in jsdoc?
- Difference between multiple arguments and options object
- Command Line Arguments in ElectronJS
- How to read command line arguments in Node.js ?
- Create a web server and run PHP script on it using Raspberry Pi
- How to create directory with HTML button and PHP ?
- How to create comma separated list from an array in PHP ?
- How to create an array for JSON using PHP?
- How to create a copy of an object in PHP?
- How to create singleton design pattern in PHP 5 ?
- PHP | Collator create() Function
- How to create an array with key value pairs in PHP?
- Why PHP script does not create a directory with 777 permissions ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.