PHP elseif Keyword
Example
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 »
Definition and Usage
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
}
}
?>
Related Pages
The if
keyword.
Read more about the if...elseif...else conditional in our PHP if else Tutorial.
❮ PHP Keywords
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.