empty "> Summary of usage examples of colon, endif, endwhile, and endfor in PHP-PHP Tutorial-php.cn

Summary of usage examples of colon, endif, endwhile, and endfor in PHP

伊谢尔伦
Release: 2023-03-11 08:00:02
Original
3801 people have browsed it

We often see a lot of strangePHP syntaxin the templates of blogging programs such as wordpress, such as:

 空的 
Copy after login

For A considerable number of PHP enthusiasts have never seen it before. What are these? Could it be that the blog developers themselves created a template language that imitates PHP?
No, in fact, these are PHP syntax, but they are not commonly used. These are alternative syntaxes for PHPProcess Control.
Here I will give you a detailed explanation of the alternative syntax of PHP process control. What is alternative syntax?
Simply put, they are some alternative ways of writing grammar.
What are the alternative syntaxes in PHP?
Flow control (including if, while, forforeach,switch) statements have alternative syntax.
Basic form of alternative syntax:
Replace the left curly brace ({) with a colon (:), replace the right curly brace (}) with endif;, endwhile;, endfor;, endforeach; and endswitch;
For example:

 是负数拉  上面的语句等同于  是负数拉 
Copy after login

Why is it almost invisible in purePHP code?
These syntaxes are a bit inconsistent with the tradition of the C family and are a bit alternative. Everyone is not used to this syntax, and it is not very convenient.
Everyone is not used to it, and what is the use of such an alternative? Does your balls hurt?
Existence is reasonable, and it has its own uses. The place where these syntaxes can be used is in the code of a mixed PHP and HTML page. The benefits are as follows:
1. Make the HTML and PHP mixed page code cleaner and neater.
What those friends who are obsessed with coding are most afraid of is messy mixed code. With these alternative syntaxes without braces, all friends who love cleanliness will be so happy that they pee.
2. The process control logic is clearer and the code is easier to read
If you want to change someone else's PHP and HTML mixed code, open it and find it, I will wipe it! What a fucking rubbish! If alternative syntax is used, I think no matter how rubbish the program developer is, his writing will not be too messy.
3. Some friends who have transferred from ASP and other basic languagefamilies will find it easier to use PHP.
Talking for a long time is useless, how about we get something to do? How to use this thing?
According to the previously described usage, the alternative syntax for the if statement is as follows:

 

等于5

等于5

不是5就是6

Copy after login

while alternative syntax:

 
  • 循环点什么
  • Copy after login

    for alternative syntax:

     
  • 循环点什么
  • Copy after login

    foreach alternative syntax:

     
  • 循环点什么
  • Copy after login

    switch alternative syntax:

    Copy after login


    The above is the detailed content of Summary of usage examples of colon, endif, endwhile, and endfor 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
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!