How to add if-else embedding inside HTML with PHP?

Spread the love

To add if-else embedding inside HTML with PHP, we use the short open tag syntax.

For instance, we write

<? if ($condition): ?>
<p>Content</p>
<? elseif ($other_condition): ?>
<p>Other Content</p>
<? else: ?>
<p>Default Content</p>
<? endif; ?>

to add if, elseif, else, and endif clauses in between our HTML code.

Leave a Reply

Your email address will not be published. Required fields are marked *