Alternative syntax in PHP (colon, endif, Endwhile, ENDfor)

Source: Internet
Author: User
Tags vars

Alternative syntax in PHP (colon, endif, Endwhile, ENDfor)reprinted October 07, 2012 09:48:10
    • Label:
    • PHP/
    • WordPress/
    • Html
    • 16096

We often see a lot of strange php syntax in the wordpress template of a blog program, such as:

[PHP]View PlainCopy
    1. <?php if (empty ($GET _[' A ')):?>
    2. <font color="Red" > Empty </font>
    3. <?php endif;?>
For a considerable part of the PHP enthusiasts have never seen, what are these things? In fact, these are PHP Process control alternative syntax, but not commonly used.
The following will give you a detailed look at the PHP Process Control alternative syntax.
1. What is an alternative syntax?
In short, it is some kind of grammatical alternative notation.

What syntax in 2.PHP has an alternative syntax?

If,while,for,forforeach,switch These process 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;
Example:
[PHP]View PlainCopy
    1. <?php if ($a <0):?>
    2. is negative pull
    3. <?php endif;?>
    4. The above statement is equivalent to
    5. <?php if ($a <0) {?>
    6. is negative pull
    7. <?php}?>

4. We're not used to it, and what's the use of such an alternative?

Existence is reasonable, it has its own usefulness, these grammars can be played in the PHP and HTML mixed page code inside. The benefits are as follows:
1) make the HTML and PHP Mix page code cleaner and neater.
2) The Process control logic is clearer and the code is easier to read.

Alternative syntax in PHP (colon, endif, Endwhile, ENDfor)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.