A function may define C++-style default values for scalar arguments as follows:
Example #3 Use of default parameters in functions
1 2 3 4 5 6 7 8 9 |
<?php function makecoffee($type = "cappuccino") { return "Making a cup of $type.\n"; } echo makecoffee(); echo makecoffee(null); echo makecoffee("espresso"); ?> |
The above example will output:
1 2 3 |
Making a cup of cappuccino. Making a cup of . Making a cup of espresso. |
PHP also allows the use of arrays and the special type NULL
as default values,