You saw nested if statements in JavaScript and you can do those in PHP as well.
if (something) {
do something
} else {
if(something else) {
do something
} else {
do a third thing
}
}
That can get big very quickly in complex pages. In PHP there is a shorthand way available as well although arguably it makes the structure less obvious.
Create a new page called elseif.php and paste this in below the h1:
$firstvalue=34;
$secondvalue=32;
if ($firstvalue==$secondvalue) {
echo "<p>the values are the same</p>";
} elseif ($firstvalue<$secondvalue) {
echo "<p>the first value is smaller</p>";
} else {
echo "<p>the second value is smaller</p>";
}
Play with the numbers and consider the messages until you understand how it works. It is exactly the same as doing this but shorter:
if ($firstvalue==$secondvalue) {
echo "<p>the values are the same</p>";
} else {
if ($firstvalue<$secondvalue) {
echo "<p>the first value is smaller</p>";
} else {
echo "<p>the second value is smaller</p>";
}
}