PHP provides some alternative syntax for flow control, including if, while, for, foreach and switch. The basic form of the alternative syntax is to replace the left curly brace ({) with a colon (:), and replace the right curly brace (}) with endif;, endwhile;, endfor;, endforeach; and endswitch; respectively.
<?php if ($a == 5): ?> A is equal to 5 <?php endif; ?>
In the example above, the HTML content "A is equal to 5" is nested within an if statement using alternative syntax. The content of this HTML is only displayed when $a is equal to 5.
Alternative syntax can also be used in else and elseif. Here is an example of an if structure including elseif and else written in an alternative syntax format:
<?php if ($a == 5): echo "a equals 5"; echo "..."; elseif ($a == 6): echo "a equals 6"; echo "!!!"; else: echo "a is neither 5 nor 6"; endif; ?>
Note:
does not support mixing the two syntaxes within the same control block.