This article mainly introduces the detailed explanation of alternative syntax in PHP. Interested friends can refer to it. I hope it will be helpful to everyone.
What is alternative syntax?
Simply put, they are some alternative ways of writing grammar.
#2. What syntaxes have alternative syntaxes in PHP?
if, while, for, forforeach, switchThese flow control statements have alternative syntax.
3. Basic form of alternative syntax:
The left curly brace ({) is replaced by a colon (:), and the right The curly braces (}) are replaced with endif;, endwhile;, endfor;, endforeach; and endswitch;
Usage:
if-endif usage:
<?php if ($a<0): ?> <li>if里面的输出</li> <?php endif; ?> 上面的语句等同于 <?php if ($a<0){ ?> if里面的输出 <?php } ?>
while-endwhile usage:
<?php while (expr): ?> <li>循环while里面的输出</li> <?php endwhile; ?>
for-endfor usage:
<?php foreach (expr1): ?> <li>循环for里面的输出</li> <?php endforeach; ?>
switch-endswitch usage:
<?php switch ($i): case 1: echo "i 等于 1"; break; case 2: echo "i 等于 2"; break; default: echo "i 不等于1和2"; endswitch; ?>
Related recommendations:
Introduction to alternative syntax in PHP, introduction to PHP alternative syntax_PHP tutorial
##Introduction to alternative syntax in PHP, introduction to PHP alternative syntax
The above is the detailed content of Detailed explanation of alternative syntax in PHP. For more information, please follow other related articles on the PHP Chinese website!