This article mainly introduces the alternative syntax in PHP. The alternative syntax in PHP is often used in template code writing. for example, this syntax is widely used in wordpress templates, if you need it, you can refer to today's wordpress code, which contains some rare Alternative php syntax,
The code is as follows:
<? Php else:?>
<? Php the_content (_ ('continue reading → ', 'thebox');?>
<? Php wp_link_pages (array ('before' =>'
'. _ ('Pages:', 'thebox'), 'after' =>'
');?>
<? Php endif;?>
What do the colons and endif after else represent? I have never met a Cainiao, so I just googled it to understand that this is an alternative syntax for php,
Colon (:) is equivalent to Left curly braces ({), and endif is equivalent to right curly braces (});
For example:
The code is as follows:
<? Php if ($ a <0):?>
Is a negative number.
The code is as follows:
<? Php endif;?>
The preceding statement is equivalent
The code is as follows:
<? Php if ($ a <0) {?>
Is a negative number.
The code is as follows:
<? Php }?>
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;
While alternative syntax:
The code is as follows:
<? Php while (expr):?>
Loop point
<? Php endwhile;?>
Other alternative syntaxes can be similar.