if elseif else
suggest changeelseif
elseif adds another condition after an if. That branch runs only when the earlier conditions were false and its own condition is true.
The following code displays either “a is bigger than b”, “a is equal to b” or “a is smaller than b”:
if ($a > $b) {
echo "a is bigger than b";
} elseif ($a == $b) {
echo "a is equal to b";
} else {
echo "a is smaller than b";
}
Several elseif statements
You can use multiple elseif statements within the same if statement:
if ($a == 1) {
echo "a is One";
} elseif ($a == 2) {
echo "a is Two";
} elseif ($a == 3) {
echo "a is Three";
} else {
echo "a is not One, Two, or Three";
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents