Else Block in Conditions for Breaking PHP Code
Now suppose we also have an else
block:
<?php if ($test) { ?>
<p>+++</p>
<?php } else { ?>
<p>---</p>
<?php } ?>
We can also rewrite it using the alternative syntax:
<?php if ($test): ?>
<p>+++</p>
<?php else: ?>
<p>---</p>
<?php endif; ?>
A variable is given:
<?php
$show = true;
?>
The code is given:
<div>
<p>text+</p>
<p>text+</p>
<p>text+</p>
</div>
<div>
<p>text-</p>
<p>text-</p>
<p>text-</p>
</div>
Output the first div if the variable show
is equal to true
, and the second div if the variable
is equal to false
.