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