Introduction to alternative syntax in PHP

Source: Internet
Author: User
Tags learn php programming
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.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.