An explanation of alternative syntax in PHP

Source: Internet
Author: User
Tags php foreach php switch
This article mainly introduces the alternative syntax in PHP, interested in the reference of friends, I hope to be helpful to everyone.

    • 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 flow 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;


Usage:

IF-ENDIF usage:

<?php if ($a <0):?>     <li>if output </li> <?php endif;?>     above statement equals <?php if ($a <0) { ?>     if the output <?php}?>

While-endwhile usage:

<?php while (expr):?>     <li> Loop while inside output </li> <?php endwhile;?>

For-endfor usage:

<?php foreach (expr1):?>     <li> loop for inside output </li> <?php Endforeach;?>

Switch-endswitch usage:

<?php switch ($i): Case     1:         echo "I equals 1";         break;     Case 2:         echo "I equals 2";         break;     Default:         echo "I is not equal to 1 and 2"; endswitch;?>

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.