<?php
$dat=date("w");
switch ($dat)
{
case 0:
print("Today is Sunday");
break;
case 1:
print("Today is Monday");
break;
case 2:
print("Today is Tuesday");
break;
case 3:
print("Today is Wednesday");
break;
case 4:
print("Today is Thursday");
break;
case 5:
print("Today is Friday");
break;
case 6:
print("Today is Saturday");
break;
} ?>
| This example is illustrate use of case statement or switch statement. You might not need that much coding to display day of the week.
There is other short functions to use. The variable
$dat is set to the day of the week and it could have values from 0 to 6, 0 is Sunday and 6 is Saturday.
Switch statement is used to display the day of the week
according to the value of variable dat.
date("w") is a function that returns a number value representing day of the week.
Execution result:
Today is Saturday
|