Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using PHP Exercise 1 Here is a set of month data for a fictitious country that d

ID: 3933778 • Letter: U

Question

Using PHP

Exercise 1

Here is a set of month data for a fictitious country that does not use the twelve-month roman calendar.

a. Write a program that finds the number of days in the shortest month and the longest month in this calendar. Ideally, you will do so without relying on loops. Instead, you should take advantage of built-in functions for exploring and manipulating arrays. You may wishto refer to the PHP documentation to identify the functions that determine the minimum and maximum values within an array.

b. Write a program that finds the total number of days in a year with this arrangement of months. Again, you should try to do so without relying on explicit loops. (You certainly should assume no knowledge of the underlying data.)

c. Write a program that prints the name of the shortest and longest month.

Exercise 2: Sorting Associative Arrays

Consider your program that prints out the table of months and the corresponding number of days in that month.

a. Suppose we arranged to sort the array before printing the table. What effect do you expectsuch sorting to have on the output?

b. Check your answer experimentally

Explanation / Answer

function getMonth($year, $month) { $last=cal_days_in_month(CAL_GREGORIAN, $month, $year); $date=new DateTime(); $res=Array(); for ($day=1;$daysetDate($year, $month, $day); $res[$day]=$date->format("l"); } return $res; } $res=getMonth(2015, 2); print_r($res); Array ( [1] => Sunday [2] => Monday [3] => Tuesday [4] => Wednesday [5] => Thursday [...] $date = time(); $days = array(); for( $day = strtotime('midnight', strtotime(date('1 F Y', $date))); /* first day of month */ $day array(31) { [1] = string(7) "Tuesday" [2] = string(9) "Wednesday" [3] = string(8) "Thursday" [4] = string(6) "Friday" [5] = string(8) "Saturday" [6] = string(6) "Sunday" [7] = string(6) "Monday" [8] = string(7) "Tuesday" [9] = string(9) "Wednesday" [10] = string(8) "Thursday" [11] = string(6) "Friday" [12] = string(8) "Saturday" [13] = string(6) "Sunday" [14] = string(6) "Monday" [15] = string(7) "Tuesday" [16] = string(9) "Wednesday" [17] = string(8) "Thursday" [18] = string(6) "Friday" [19] = string(8) "Saturday" [20] = string(6) "Sunday" [21] = string(6) "Monday" [22] = string(7) "Tuesday" [23] = string(9) "Wednesday" [24] = string(8) "Thursday" [25] = string(6) "Friday" [26] = string(8) "Saturday" [27] = string(6) "Sunday" [28] = string(6) "Monday" [29] = string(7) "Tuesday" [30] = string(9) "Wednesday" [31] = string(8) "Thursday" }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote