We often see a lot of strange PHP syntax in the templates of blogging programs such as wordpress, such as:
[php] view
plaincopy
- if(empty($GET_['a'])): ?>
- < font color="red">empty
- endif; ?>
For quite a few PHP enthusiasts, this is simply not possible. I've never seen them before. What are these? In fact, these are alternative syntaxes for PHP process control, but they are not commonly used.
Now I will give you a detailed explanation of the alternative syntax for PHP process control.
1. What is alternative syntax?
Simply put, they are some alternative ways of writing grammar.
2. Which syntaxes in PHP have alternative syntaxes?
Flow control statements such as if, while, for, forforeach, and switch have alternative syntax.
3. The basic form of alternative syntax:
Replace the left curly brace ({) with a colon (:), replace the right curly brace (}) with endif;, endwhile;, endfor;, endforeach; and endswitch respectively ;
Example:
[php] view
plaincopy
- if ($a<0): ?>
- is a negative number
- endif ; ?>
-
- The above statement is equivalent to
- if ($a<0){ ?>
- It’s a negative number
-
4. No one is used to it, and what’s the use of having him so different?
Existence is reasonable, and it has its own uses. The place where these syntaxes can be used is in the code of a mixed PHP and HTML page. The benefits are as follows:
1) Make the HTML and PHP mixed page code cleaner and neater.
2) The process control logic is clearer and the code is easier to read.
The above introduces PHP: colon, endif, endwhile, endfor, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.