Cover all cases with if-elseif-else in PHP

Description

The following code shows how to cover all cases with if-elseif-else.

Example


<?php/*from w  w w.  j av  a2  s .c  om*/
  /*
  ** Get today's weekday name
  */
  $englishDay = date("l");

  /*
  ** Find the today's German name
  */
  if($englishDay == "Monday")
  {
    $deutschDay = "Montag";
  }
  elseif($englishDay == "Tuesday")
  {
    $deutschDay = "Dienstag";
  }
  elseif($englishDay == "Wednesday")
  {
    $deutschDay = "Mittwoch";
  }
  elseif($englishDay == "Thursday")
  {
    $deutschDay = "Donnerstag";
  }
  elseif($englishDay == "Friday")
  {
    $deutschDay = "Freitag";
  }
  elseif($englishDay == "Saturday")
  {
    $deutschDay = "Samstag";
  }
  else
  {
    // 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