• 🏠 Home
  • 🧰 Online Generators
  • 📰 Blog
  • 🔎 Search
  • 📧 Contact
  • 📘 Guestbook
  • 🗞️ News
  • 💰 Support
  • ℹ️ Info: The website has been modernized to improve readability and smartphone compatibility. Feel free to report any bugs using the contact form

    switch statement


    Overview

    The switch statement is equivalent to a set of "if" instructions. It allows you to run different parts of code depending on the value to which it is equal.

    Codes Example (with numerical values):

    <?php
     switch ($i) {
      case 0:
        echo "i is equal to 0";
        break;
      case 1:
        echo "i is equal to 1";
        break;
      case 2:
        echo "i is equal to 2";
        break;
      default:
        echo "i is outside the limits";
     }
    ?>

    Codes Examples (with strings):

    <?php
     switch ($i) {
      case "OK":
        echo "The test is OK.";
        break;
      case "incompatible":
        echo "The solution is incompatible.";
        break;
      case "KO":
        echo "Incorrect test.";
        break;
     }
    ?>
    Go back


    (c) 2005-2025 Jérôme DESMOULINS
    Data privacy