Write a program to show day of the week using switch

Description:

Write a program to show day of the week (for example: Monday) based on numbers using switch/case statements.

Conditions:

  • You can pass 1 to 7 number in switch
  • Day 1 will be considered as Monday
  • If number is not between 1 to 7, show invalid number in default

View Solution/Program

<?php
$day = "5";
 
switch ($day) {
    case "1":
        echo "It is Monday!";
        break;
    case "2":
        echo "It is today!";
        break;
    case "3":
        echo "It is Wednesday!";
        break;
	case "4":
        echo "It is Thursday!";
        break;
    case "5":
        echo "It is Friday!";
        break;
    case "6":
        echo "It is Saturday!";
        break;
	case "7":
        echo "It is Sunday!";
        break;
    default:
        echo "Invalid number!";
}
?>
Tutorials Class - Output Window

It is Friday!


Learn more about the similar topics:
Tutorials
PHP Decision Making
Exercises & Assignments
Write a program to check student grade based on marks
Write a program to show day of the week using switch
Write a program to calculate Electricity bill in PHP
Write a simple calculator program in PHP using switch case
Write a PHP program to check if a person is eligible to vote
Write a PHP program to check whether a number is positive, negative or zero
Interview Questions & Answers
No Content Found.