Conditions and Breaking PHP Code
Let's say we have some variable:
<?php
$test = true;
?>
Let's output some piece of HTML
code if our variable is equal to true:
<?php
if ($test) {
echo '<p>text</p>';
}
?>
We can rewrite this code to the following, with a break in PHP brackets:
<?php if ($test) { ?>
<p>text</p>
<?php } ?>
This can be simplified even more by using
the alternative if syntax:
<?php if ($test): ?>
<p>text</p>
<?php endif; ?>
Given a variable:
<?php
$show = true;
?>
Given the code:
<div>
<p>text1</p>
<p>text2</p>
<p>text3</p>
</div>
Output the provided HTML code if the variable
show is equal to true.