PHP provides alternative syntaxes for process control, including if, while, for, foreach, and switch. The basic form of the alternative syntax is to replace left curly braces ({) with colons (:) and right curly braces (}) with endif;, endwhile;, endfor;, endforeach; and endswitch ;. PHP provides alternative syntaxes for process control, including if, while, for, foreach, and switch. The basic form of the alternative syntax is to replace left curly braces ({) with colons (:) and right curly braces (}) with endif;, endwhile;, endfor;, endforeach; and endswitch ;.
A is equal to 5
In the preceding example, the HTML content "A is equal to 5" is nested in the if statement with the substitution syntax. The HTML content is only displayed when $ a is equal to 5.
The alternative syntax can also be used in else and elseif. The following is an example of an if structure that includes elseif and else written in an alternative syntax format:
Note:
You cannot use two syntaxes in the same control block.