PHP IF – Else – Elseif
PHP IF – Else – Elseif
Syntax
if (condition) {
if condition is true then execute statement
}
if (condition) {
if condition is true then execute statement
} else {
if condition is false then execute statement
}
if (A) {
if A is true then execute statement
} elseif (B) {
if A is false and B is true then execute statement
} else {
if both A and B are false then execute statement
}
Example
<html>
<body>
<?php
$a = 5;
$b = 7;
if ($a <= 5) {
echo "A is true!";
} elseif ($b > 5) {
echo "B is true!";
} else {
echo "A and B are false!";
}
?>
</body>
</html>
Result
A is true!