PHP alternative syntax for Process Control

Source: Internet
Author: User

PHP Process Control Alternative syntax (the alternative syntax of the PHP Process Control) as early as PHP 4. Time has existed, but there is not much to use.
##
So, what syntax in PHP has an alternative syntax?

##
There are alternative syntax for the process control statements, including the If,while,for,foreach and switch statements.

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;
##

Application

Typically, the above substitution syntax is generally not used in pure PHP code in order to keep the readability of the other popular statements as consistent as possible. However, in Web language, when you use PHP development, you will often see the alternative syntax of the process statement.
That is, the syntax can be played in the code of the PHP and HTML mixed pages. The benefits are as follows:

1. Make the HTML and PHP Mix page code cleaner and neater.

A friend with code cleanliness is most afraid of a messy mix of code, with these no curly braces alternative syntax, you love clean friends happy to pee.

2. Process Control logic clearer, code easier to read

To change someone else's PHP and HTML mixed code, open Find, I wipe! It's so damn rubbish! If you use the alternative syntax, I think the garbage program developers are not too messy to write.

3. Some friends from other basic language families, such as ASP, will be more likely to use PHP.

##
A typical example is in the WordPress site code that you will often see. Examples are as follows:

<?php/** * The template for displaying the header * * Displays all of the head element and everything up until the ' sit E-content "Div. * * @package WordPress * @subpackage Twenty_fifteen * @since Twenty Fifteen 1.0 */?><! DOCTYPE html>
上述代码来自于著名的Twenty_Fifteen主题中的header.php文件定义。

PHP alternative syntax for Process Control

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.