Close Menu
    Facebook X (Twitter) Instagram
    Oixiesoft
    • Home
    • Services
      • WordPress Malware Removal
      • Fix WordPress Errors
      • WordPress Website Development
    • Articles
    • Contact
    Oixiesoft
    Home»Tutorial»PHP»The PHP switch Statement
    PHP

    The PHP switch Statement

    Editorial StaffBy Editorial StaffUpdated:April 30, 2022No Comments1 Min Read
    Share
    Facebook Twitter LinkedIn Pinterest Email

    The PHP switch Statement

    The switch-case statement is used when performing one statement from numerous conditions.

    Syntax

    switch (n) {
      case label1:
        code to be executed if n=label1;
       break;
     case label2:
        code to be executed if n=label2;
       break;
     case label3:
        code to be executed if n=label3;
       break;
      ...
      default:
       code to be executed if n is different from all labels;
    }
    

    Example

    $fruits = "apple";
    
    switch ($fruits) {
      case "apple":
        echo "This is a apple!";
        break;
      case "mango":
        echo "This is a mango!";
        break;
      case "kiwi":
        echo "This is a kiwi!";
        break;
      default:
        echo "This is neither apple, mango, nor kiwi!";
    }
    

    In a switch statement, the block of code runs queue by queue and once a tome PHP finds a case statement that considers true, it’s not ending the execution, but also executes all the blocks of code till the end of the switch statement automatically.

    Share. Facebook Twitter Pinterest LinkedIn WhatsApp Reddit Tumblr Email
    Editorial Staff

    Related Posts

    CodeIgniter vs Laravel: A Detailed Side-by-Side Comparison

    Python Arrays

    Python Lambda

    PHP
    • PHP Comments
    • PHP if else Statements
    • The PHP switch Statement
    • PHP Functions
    • PHP for Loop
    • PHP Arrays
    • PHP Include Files
    • PHP Date() and Time() Function
    • PHP Forms Tutorial
    Services
    • Web Development
    • Mobile Application Development
    • WordPress Malware Removal Service
    • Website Design
    • WordPress Development
    • Magento Development
    • Shopify Development
    • SEO Services
    Blog
    • How to Fix the Error Establishing a Database Connection
    • Ping List WordPress
    • How To Fix Japanese Keyword Hack
    • How to remove Malware from WordPress
    Hire Developers
    • Hire WordPress Developer
    • Hire Shopify Developer
    Contact Info
    • Oixiesoft Technologies
      A-40, Block A, I thum Tower, Sector 62, Noida
    • [email protected]
    • Privacy Policy
    • About Us
    • Contact Us
    © 2025 OixieSoft Technologies

    Type above and press Enter to search. Press Esc to cancel.