How to make a day finder in php

Day finder program shows us day name of the week from numeric value such as: 1,2,3,4.. upto 7.

If we consider Saturday=1, Sunday=2, Monday=3, Tuesday=4, Wednesday=5, Thursday=6 & Friday=7.

Then we can simply make a day finder program in php which shows us the day name from the day number.

We can make the day finder easily by using array and switch in php.

Firstly, we will create an array of days:

$days = array(1=>"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday");

We have put ‘1=>’ to index the array from number 1. If you don’t use it, then the array will start from number 0 & consider Saturday=1,…,Friday=6 respectively.

We will create a variable and assign our desired number to output the name of the desired day. Let the desired day be friday and we will assign number 7 to output friday.



Now we will make a switch statement to output the day name from the given value.

        case 1: echo $days[1];
        case 2: echo $days[2];
        case 3: echo $days[3];
        case 4: echo $days[4];
        case 5: echo $days[5];
        case 6: echo $days[6];
         case 7: echo $days[7];
        default: echo "Invalid input! Please enter day number between 1-7";

If all continues well, then the output will Friday.