Test a second condition if the first condition is not met:
<?php
if(5 < 3) {
echo "Five is less than three";
} else if(5 > 4) {
echo "Five is greater than four";
}
?>
Try it Yourself »
The elseif
keyword tests a new condition if the condition of a previous if
or elseif
statement was not met. It is equivalent to putting an if
statement inside an else block.
The following blocks of code are equivalent:
<?php
if (...) {
some code here
} elseif (...) {
some code here
}
?>
<?php
if (...) {
some code here
} else{
if (...) {
some code here
}
}
?>
The if
keyword.
Read more about the if...elseif...else conditional in our PHP if else Tutorial.
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!