Detailed explanation of alternative syntax in PHP

墨辰丷
Release: 2023-03-25 19:48:02
Original
1885 people have browsed it

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 } ?>
Copy after login

while-endwhile usage:

<?php while (expr): ?> 
    <li>循环while里面的输出</li> 
<?php endwhile; ?>
Copy after login

for-endfor usage:

<?php foreach (expr1): ?> 
    <li>循环for里面的输出</li> 
<?php endforeach; ?>
Copy after login

switch-endswitch usage:

<?php 
switch ($i): 
    case 1: 
        echo "i 等于 1"; 
        break; 
    case 2: 
        echo "i 等于 2"; 
        break; 
    default: 
        echo "i 不等于1和2"; 
endswitch; 
?>
Copy after login

Related recommendations:

php alternative syntax

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template