Hi,
For example:
PHP Code:
if ($num < 0)
{
print '$num is negative';
}
elseif ($num == 0)
{
print '$num is zero';
}
elseif ($num > 0)
{
print '$num is positive';
}
The last elseif could be substituted with an else because, if $num is not
negative and not zero, it must be positive.
Both styles of the if construct behave in the same way. While the statement
style is probably more readable and convenient for use inside PHP code
blocks, the statement list style extends readability when used to conditionally
display HTML blocks. Here’s an alternative way to implement the previous
example using HTML blocks instead of print:
HTML Code:
<?php if ($num < 0): ?> <h1>$num is negative</h1> <?php elseif($num == 0): ?> <h1>$num is zero</h1> <?php elseif($num > 0): ?>
<h1>$num is positive</h1> <?php endif; ?>
As you can see, HTML blocks can be used just like any other statement.
Here, only one of the HTML blocks are displayed, depending on the value of
$num.