How can I pass an optional parameter to a PHP function. For example
function test($required, $optional){..}
So that i should be able to call the function by passing either one parameter or both. For example:
test($required, $optional) test($required);
Thanks.
try this:
function test($required, $optional = NULL){..}
then you can call
test($required, $optional)
and with $optional
null
test($required);
With a default value:
function test($required, $optional="default value"){..}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With