IF Statement
If an expression isTRUE then execute a statement.if (expression) {
statement;
}Example
$a = 2; $b = 4;Result
if ($a < $b) { echo 'a is smaller than b'; }
a is smaller than bBut what if the expression is
FALSE?IF, ELSE Statement
If an expression isTRUE do this, if FALSE do that.if (expression) {
statement;
} else {
statement;
}Example
$a = 6; $b = 4;Result
if ($a < $b) { echo 'a is smaller than b'; } else { echo 'a is not smaller than b'; }
a is not smaller than bWhat if you want to check more than one expression?
IF, ELSE IF, ELSE Statement
Testing multiple expression ifTRUE then execute default statement if FALSEif (expression) {
statement;
} elseif (expression) {
statement;
} else {
statement;
}Example
$a = 4; $b = 4;Result
if ($a < $b) { echo 'a is smaller than b'; } else if ($a == $b) { echo 'a equals b'; } else { echo 'a is not smaller than b'; }
a equals b
No comments:
Post a Comment