Home > Backend Development > PHP Tutorial > Introduction to alternative syntax in PHP, introduction to PHP alternative syntax_PHP tutorial

Introduction to alternative syntax in PHP, introduction to PHP alternative syntax_PHP tutorial

WBOY
Release: 2016-07-13 10:09:56
Original
1277 people have browsed it

Introduction to alternative syntax in PHP, introduction to PHP alternative syntax

I took a look at the wordpress code today, and there are some rare php alternative syntaxes in it,

Copy code The code is as follows:


         

                                                                                                                                                   'What do the colon and endif after else mean? I'm a newbie, I haven't seen it before, so I googled it and realized that this is an alternative syntax for PHP,

Colon (:) is equivalent to the left curly bracket ({), endif is equivalent to the right curly bracket (});

Give me an example:


Copy code The code is as follows:


It’s a negative number


Copy code The code is as follows:


The above statement is equivalent to


Copy code The code is as follows:


It’s a negative number


Copy code The code is as follows:


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 (:), and replace the right curly brace (}) with endif;, endwhile;, endfor;, endforeach; and endswitch;

while alternative syntax:


Copy code The code is as follows:
  • What to loop




  • Other alternative syntaxes can be derived by analogy.

    http://www.bkjia.com/PHPjc/940494.html

    truehttp: //www.bkjia.com/PHPjc/940494.htmlTechArticleIntroduction to alternative syntax in PHP, introduction to PHP alternative syntax Today I looked at the wordpress code, and there are some rare php in it Alternative syntax, copy the code as follows: php else : div class="...
    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