PHP Switch SELECT statement Detail instance

Source: Internet
Author: User
Tags php switch

A switch statement is like a series of if statements to the same expression. In many times, you want to compare the same variable (or expression) with many different values, and perform different pieces of the program based on different comparison results. This is the use of the switch statement.

The following two examples do the same thing in different ways, one with a set of if statements and the other with a SWITCH statement:

  code is as follows copy code

/* Example 1  */
if ($i = = 0) {
print "I equals 0";     
}
if ($i = = 1) {
print "I equals 1";
   
if ($i = = 2) {
print "I equals 2";
    

/* Example 2 */
Switch ($i) {
Case 0:
print "I equals 0";
Break     
Case 1:
print "I equals 1";
Break     
Case 2:
print "I equals 2";
Break
}

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.