This article mainly introduces the alternative syntax in PHP, which is a common but important usage in PHP programming, if you need it, you can refer to the alternative syntax. it is a very important concept that is not often seen in PHP programming. Today, this article demonstrates the usage of this concept in the form of instances.
Check the wordpress code, which shows some rare Alternative php syntax, as shown below:
<?php else : ?> <?php the_content( __( 'Continue reading →', 'thebox' ) ); ?> <?php wp_link_pages( array( 'before' => '
' . __( 'Pages:', 'thebox' ), 'after' => '
' ) ); ?>
<?php endif; ?>
Many readers may have the following question: What is the colon and endif behind else? Google can understand that this is the alternative syntax of php.
The colon (:) is equivalent to the left curly braces ({), and the endif is equivalent to the right curly braces (});
Here is an example:
<? Php if ($ a <0):?> // Negative number <? Php endif;?>
The preceding statement is equivalent:
<? Php if ($ a <0) {?> // Negative number <? Php }?>
Which of the following syntaxes 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:
<? Php while (expr):?>
Loop content<? Php endwhile;?>
Other alternative syntaxes can be similar.
I hope this article will help you learn PHP programming.