Question
$monthDays = array ('January' => 31, 'February' => 28, 'March' => 31, 'April' => 30, 'May' => 31, 'June' => 30, 'July' => 31, 'August'
$monthDays = array ('January' => 31, 'February' => 28, 'March' => 31, 'April' => 30, 'May' => 31, 'June' => 30, 'July' => 31, 'August' => 31, 'September' => 30, 'October' => 31, 'November' => 30, 'December' => 31);
Write a PHP program that will display the month which has the minimum number of days (There is only one such month), and a month which has the maximum number of days (There are 7 months which have such a maximum. Your program needs only display one of them.). The algorithm that you devise must be coded in a function. Use a foreach loop to traverse the array. Your program must not use any built-in PHP function other than the echo function. The algorithm logic for finding a month with a minimum number of days, and a month with a maximum number of days must only use basic PHP operators and constructs. Hint: Within the loop, use two variables, say $min and $max. $min should be initialized to a value > 31, and $max should be initialized to a value These two variables will hold the current values for the minimum number of days and the maximum number of days as the loop traversal progresses. You will also need two variables to hold the names of the months. Traverse the array all the way through.
The program should output the month name and the number of days for both the minimum and maximum using the echo function. Example Output: February has the minimum number of days: 28 December has a maximum number of days: 31
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started