July 26, 2017

Core PHP: The Switch Statement (5.13)

default


The default statement is used if no match is found.

$x=5;
switch ($x) {
  case 1:
    echo "One";
    break;
  case 2:
    echo "Two";
    break;
  default:
    echo "No match";
}

//Outputs "No match"

The default statement is optional, so it can be omitted.

No comments:

Post a Comment