PHP: Colon, endif, Endwhile, endfor

Source: Internet
Author: User
Tags vars

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

[PHP]View Plaincopy
  1. <?phpif(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 Endif;,endwhile;,endfor;,endforeach; and Endswitch;
Example:
[PHP]View Plaincopy
  1. <? php  if   ( $ A <0): ?>   
  2.      is a 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.

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.