Alternative syntax in PHP (colon, endif, Endwhile, ENDfor)reprinted October 07, 2012 09:48:10
- Label:
- PHP/
- WordPress/
- Html
We often see a lot of strange php syntax in the wordpress template of a blog program, such as:
[PHP]View PlainCopy
- <?php if (empty ($GET _[' A ')):?>
- <font color="Red" > Empty </font>
- <?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
- <?php if ($a <0):?>
- is negative pull
- <?php endif;?>
- The above statement is equivalent to
- <?php if ($a <0) {?>
- is negative pull
- <?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)