PHP switch Keyword

PHP throw Keyword
PHP static Keyword

In this article, you will learn how to use switch keyword in PHP. The switch keyword in PHP is used to create a switch conditional.

Switch conditionals choose a block of code to run based on the value of an expression.

examples of the SWITCH function

Example 1. In this example, we choose a message to display based on the value of a variable.

<?php
$favcolor = "red";

switch ($favcolor) {
  case "red":
    echo "Your favorite color is red!";
    break;
  case "blue":
    echo "Your favorite color is blue!";
    break;
  case "green":
    echo "Your favorite color is green!";
    break;
  default:
    echo "Your favorite color is neither red, blue, nor green!";
}
?>
PHP throw Keyword
PHP static Keyword

Stay up-to-date about PHP!

We don’t spam!

en English
X
Scroll to Top