I have function as below.
function test($username, $is_active=1, $sent_email=1, $sent_sms=1) {
echo $sent_email; // It should print default ie 1
}
Call to function :
test($username, 1, null, 1);
How to call function if need to use default value in function. $sent_email should be 1. Can not change sequence of parameter.
When you start the value parameters happens:
function makecoffee($type = "cappuccino")
{
return "Making a cup of $type.\n";
}
echo makecoffee();
echo makecoffee(null);
echo makecoffee("espresso");
?>
The above example will output:
Making a cup of cappuccino.
Making a cup of .
Making a cup of espresso.
To fulfill what you want to check with conditions as follows:
function test($username, $is_active=1, $sent_email=1, $sent_sms=1) {
if($sent_email!=1)
$sent_email=1;
echo $sent_email; // It should print default ie 1
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments