Cover all cases with switch in PHP

Description

The following code shows how to cover all cases with switch.

Example


<?php/*  www  .ja v a 2s .c  o m*/
  /*
  ** Get today's weekday name
  */
  $englishDay = date("l");

  /*
  ** Find the today's German name
  */
  switch($englishDay)
  {
    case "Monday":
      $deutschDay = "Montag";
      break;
    case "Tuesday":
      $deutschDay = "Dienstag";
      break;
    case "Wednesday":
      $deutschDay = "Mittwoch";
      break;
    case "Thursday":
      $deutschDay = "Donnerstag";
      break;
    case "Friday":
      $deutschDay = "Freitag";
      break;
    case "Saturday":
      $deutschDay = "Samstag";
      break;
    default:
      // It must be Sunday
      $deutschDay = "Sonntag";
  }

  /*
  ** Print today's English and German names
  */
  print("<h2>German Lesson: Day of the Week</h2>\n" .
    "<p>\n" .
    "In English: <b>$englishDay</b>.<br>\n" .
    "In German: <b>$deutschDay</b>\n" .
    "</p>\n");
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Language Basic »




PHP Introduction
PHP Operators
PHP Statements
Variable
PHP Function Create
Exception
PHP Class Definition