The alternative syntax that is not commonly used in PHP process control is used to prepare a wordpress topic. the following syntax is displayed:
__( 'Previous page', 'twentyfifteen' ), 'next_text' => __( 'Next page', 'twentyfifteen' ), 'before_page_number' => '' . __( 'Page', 'twentyfifteen' ) . ' ', ) ); // If no content, include the "No posts found" template. else : get_template_part( 'content', 'none' ); endif; ?>
This knows that php has a less commonly used alternative syntax: according to the http://www.jb51.net/article/23252.htm
Which of the following statements in PHP have alternative syntaxes?
Process control (including if, while, forforeach, switch) statements have alternative syntax.
The basic form of alternative syntax:
Replace Left curly braces ({) with colons (:), and change right curly braces (}) with endif;, endwhile;, endfor;, endforeach; and endswitch;
For example:
The code is as follows:
Is a negative number.
The preceding statement is equivalent
Is a negative number.
Why is it almost invisible in pure PHP code?
These syntaxes are a little different from the C family's tradition. they are not used to these syntaxes and are not very convenient.
Everyone is not used to it. what is the use of this alternative? Does it hurt?
Existence is reasonable, and it has its own use. these syntaxes can be used in the code of PHP and HTML hybrid pages. Benefits:
1. make the HTML and PHP mixed page code clean and tidy.
Friends who have code cleansing are most afraid of mixed code. with these alternative syntaxes without curly braces, you may be happy to have a natural sensation.
2. clearer process control logic and easier code reading
I want to change the mixed PHP and HTML code of others. I will clean it! Too much TMD junk! If the alternative syntax is used, I don't think it's too messy for junk program developers.
3. some friends who transfer from ASP and other basic language families will be more likely to use PHP.
It's useless for half a day. what can I do? How to use this item?
According to the previous usage method, the alternative syntax of the if statement is as follows:
The code is as follows:
Equal to 5
Equal to 5
5 or 6
While alternative syntax:
The code is as follows:
Loop point
For alternative syntax:
The code is as follows:
Loop point
Foreach alternative syntax:
The code is as follows:
Loop point
Switch substitution syntax:
The code is as follows:
Switch ($ I ):
Case 0:
Echo "I equals 0 ";
Break;
Case 1:
Echo "I equals 1 ";
Break;
Case 2:
Echo "I equals 2 ";
Break;
Default:
Echo "I is not equal to 0, 1 or 2 ";
Endswitch;
?>
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.