Testing the Switch Statement

The code sets $english_Day to the value of the current day and uses the variable to test for the day of the week. The day of the week is printed out below for English and German.

Start PHP Code RESULT

German lesson: Day of the week

$english_day: Thursday
In English, today is: Thursday .
In German, today is: Sonntag.
End PHP Code RESULT

The PHP Code START
<?
/*
/** Get today's weekday name
*/

$english_Day = date("1");

/*
/** Get today's German weekday name
*/
switch($english_Day)
{
  case "Monday":
    $deutsche_Day = "Montag";
    break;
  case "Tuesday":
    $deutsche_Day = "Dienstag";
    break;
  case "Wednesday":
    $deutsche_Day = "Mittwoch";
    break;
  case "Thursday":
    $deutsche_Day = "Donnerstag";
    break;
  case "Friday":
    $deutsche_Day = "Freitag";
    break;
  case "Saturday":
    $deutsche_Day = "Samstag";
    break;
  default:
    // It MUST be Sunday
    $deutsche_Day = "Sonntag";
}

/*
/** Print today's English and German names.
*/

print("<h2>German lesson: Day of the week\n");
print("In English, today is:" . date("1") . ".<br>\n");
print("In German, today is:" $deutsche_Day.<br>\n");
?>
The PHP Code END

Back to Bill's PHP