This article mainly introduces the alternative syntax in PHP, interested in the reference of friends, I hope to be helpful to everyone.
What syntax in 2.PHP has an alternative syntax?
if, while, for, Forforeach, switch These flow control statements have alternative syntax.
3. The basic form of alternative syntax:
The left curly brace ({) is replaced by a colon (:) and the right curly brace (}) is replaced by a endif;,endwhile;,endfor;,endforeach; and Endswitch;
Usage:
IF-ENDIF usage:
<?php if ($a <0):?> <li>if output </li> <?php endif;?> above statement equals <?php if ($a <0) { ?> if the output <?php}?>
While-endwhile usage:
<?php while (expr):?> <li> Loop while inside output </li> <?php endwhile;?>
For-endfor usage:
<?php foreach (expr1):?> <li> loop for inside output </li> <?php Endforeach;?>
Switch-endswitch usage:
<?php switch ($i): Case 1: echo "I equals 1"; break; Case 2: echo "I equals 2"; break; Default: echo "I is not equal to 1 and 2"; endswitch;?>