Question

PHP Question: _____________________________________________ Write the PHP code to list out all of the dates of the...

PHP Question:

_____________________________________________

Write the PHP code to list out all of the dates of the current month and assign them to their given days. As an example, for the month of October 2020, the output should look something like this:

October 2020      

Monday: 5, 12, 19, 26

Tuesday: 6, 13, 20, 27

Wednesday: 7, 14, 21, 28

Thursday: 1, 8, 15, 22, 29

Friday: 2, 9, 16, 23, 30

Saturday: 3, 10, 17, 24, 31

Sunday: 4, 11, 18, 25


IMPORTANT: The code MUST use the current month, whatever the current month is at the time (so if I used this PHP code during July of 2020, it would use all of the dates of July 2020 and assign them to the proper days). Do NOT use tables for this code.

Homework Answers

Answer #1

Php Code

<?php

//create array for stored dates
$monday = array();
$tuesday = array();
$wednesday = array();
$thursday = array();
$friday = array();
$saturday = array();
$sunday = array();

$date = date("Y-m-d"); // get current date
$month = date("m"); // get current month
$year = date("Y"); // get current year

$last_date = date("t", strtotime($date)); //get last date in current month
$m=$tu=$w=$th=$f=$sa=$su = 0; // assign same value to multiple variable at once

//Print current month and year
if($month == "01")
{
   echo "January ".$year."<br>";
}
elseif ($month == "02") {
   echo "February ".$year."<br>";
}
elseif ($month == "03") {
   echo "March ".$year."<br>";
}
elseif ($month == "04") {
   echo "April ".$year."<br>";
}
elseif ($month == "05") {
   echo "May ".$year."<br>";
}
elseif ($month == "06") {
   echo "June ".$year."<br>";
}
elseif ($month == "07") {
   echo "July ".$year."<br>";
}
elseif ($month == "08") {
   echo "August ".$year."<br>";
}
elseif ($month == "09") {
   echo "September ".$year."<br>";
}
elseif ($month == "10") {
   echo "October ".$year."<br>";
}
elseif ($month == "11") {
   echo "November ".$year."<br>";
}
elseif ($month == "12") {
   echo "December ".$year."<br>";
}

for($i=1;$i<=$last_date;$i++) // for loop start first date to last date in current month
{
   $day = date("l", mktime(0,0,0,$month,$i,$year));//get day of each date (change date using i variable)
   //compare day if true store date in array
   if($day == "Monday")
   {
       $monday[$m++] = $i;
   }
   elseif ($day == "Tuesday") {
       $tuesday[$tu++] = $i;
   }
   elseif ($day == "Wednesday") {
       $wednesday[$w++] = $i;
   }
   elseif ($day == "Thursday") {
       $thursday[$th++] = $i;
   }
   elseif ($day == "Friday") {
       $friday[$f++] = $i;
   }
   elseif ($day == "Saturday") {
       $saturday[$sa++] = $i;
   }
   elseif ($day == "Sunday") {
       $sunday[$su++] = $i;
   }
}

$monDate=$tueDate=$wedDate=$thuDate=$friDate=$satDate=$sunDate=""; // assign same value to multiple variable at once

//start Monday
echo "Monday: ";
for($i=0;$i<sizeof($monday);$i++)
{
   $monDate = $monDate.$monday[$i].", ";//concate string of monday dates
}
echo substr(trim($monDate), 0, -1);//use substr and trim function or remove the last comma in string
echo "<br>";
//end Monday

//start Tuesday
echo "Tuesday: ";
for($i=0;$i<sizeof($tuesday);$i++)
{
   $tueDate = $tueDate.$tuesday[$i].", ";//concate string of tuesday dates
}
echo substr(trim($tueDate), 0, -1);
echo "<br>";
//end Tuesday

//start Wednesday
echo "Wednesday: ";
for($i=0;$i<sizeof($wednesday);$i++)
{
   $wedDate = $wedDate.$wednesday[$i].", ";//concate string of wednesday dates
}
echo substr(trim($wedDate), 0, -1);
echo "<br>";
//end Wednesday

//start Thursday
echo "Thursday: ";
for($i=0;$i<sizeof($thursday);$i++)
{
   $thuDate = $thuDate.$thursday[$i].", ";//concate string of thursday dates
}
echo substr(trim($thuDate), 0, -1);
echo "<br>";
//end Thursday

//start Friday
echo "Friday: ";
for($i=0;$i<sizeof($friday);$i++)
{
   $friDate = $friDate.$friday[$i].", ";//concate string of friday dates
}
echo substr(trim($friDate), 0, -1);
echo "<br>";
//end Friday

//start Saturday
echo "Saturday: ";
for($i=0;$i<sizeof($saturday);$i++)
{
   $satDate = $satDate.$saturday[$i].", ";//concate string of saturday dates
}
echo substr(trim($satDate), 0, -1);
echo "<br>";
//end Saturday

//start Sunday
echo "Sunday: ";
for($i=0;$i<sizeof($sunday);$i++)
{
   $sunDate = $sunDate.$sunday[$i].", ";//concate string of sunday dates
}
echo substr(trim($sunDate), 0, -1);


?>

===============================OUTPUT============================

==Please Upvote==

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Use the given categorical data to construct the relative frequency distribution. Natural births randomly selected from...
Use the given categorical data to construct the relative frequency distribution. Natural births randomly selected from four hospitals in a highly populated region occurred on the days of the week​ (in the order of Monday through​ Sunday) with the frequencies 54​, 63​, 71​, 57​, 55​, 45​, 55. Does it appear that such births occur on the days of the week with equal​ frequency? Construct the relative frequency distribution. Day Relative Frequency Monday nothing​% Tuesday nothing​% Wednesday nothing​% Thursday nothing​% Friday...
MW is a large discount store that operates seven days per week. The store needs the...
MW is a large discount store that operates seven days per week. The store needs the following number of full-time employees working each day of the week. Sunday Monday Tuesday Wednesday Thursday Friday Saturday num of employees 188 88 112 140 136 172 212 Each employee must work five consecutive days each week and then have two days off. For example, any employee who works Sunday through Thursday has Friday and Saturday off. The store currently has a total of...
So, the brewery selected it’s place and now needs to hire folks. After some testing, they...
So, the brewery selected it’s place and now needs to hire folks. After some testing, they expect to have approximately 2,000 customers per week. Since they will be open 7 days a week, they need to hire people to help serve their beer. They know that Friday and Saturday will drive sales. Between these 2 days, they will get 50% of their weekly sales. So, Friday has 25% of sales and Saturday has 25% of the sales. As for Sunday...
Each observation in a random sample of 99 bicycle accidents resulting in death was classified according...
Each observation in a random sample of 99 bicycle accidents resulting in death was classified according to the day of the week on which the accident occurred. Data consistent with information are given in the following table. Based on these data, is it reasonable to conclude that the proportion of accidents is not the same for all days of the week? Use α = 0.05. (Round your answer to two decimal places.) Day of Week Frequency Sunday 13 Monday 12...
d = int(input('Enter the date: ')) m = int(input('Enter the month: ')) y = int(input('Enter the...
d = int(input('Enter the date: ')) m = int(input('Enter the month: ')) y = int(input('Enter the year: ')) if m<3: m = m + 12 y = y - 1 a = (2*m) + (6*(m+1)/10) b = y + (y/4) + (y/400) - (y/100) c = d + a + b + 1 f = c / 7 if f == 0: print ('Sunday') elif f == 1: print ('Monday') elif f == 2: print ('Tuesday') elif f ==3: print...
Need linear solution using Excel Solver. Cannot use an IF statement or it isn't linear. On...
Need linear solution using Excel Solver. Cannot use an IF statement or it isn't linear. On Monday morning, you have $3000 in cash on hand. For the next seven days, the following cash requirements must be met: Monday, $5000; Tuesday, $6000; Wednesday, $9000; Thursday, $2000; Friday, $7000; Saturday, $2000; Sunday, $3000. At the beginning of each day, you must decide how much money (if any) to withdraw from the bank. It costs $10 to make a withdrawal of any size....
The firm is an all-equity firm with assets worth $350 million and 100 million shares outstanding....
The firm is an all-equity firm with assets worth $350 million and 100 million shares outstanding. It plans to borrow $100 million and use these funds to repurchase shares. The firm’s marginal corporate tax is 21%, and it plans to keep its outstanding debt equal to $100 million permanently. If the firm manages to repurchase shares at $4 per share, what is the per share value of equity for the leveraged firm? A) $2.71 per share B) $3.5 per share...
At a western hospital, there were a total of 932 births in 20 consecutive weeks. Of...
At a western hospital, there were a total of 932 births in 20 consecutive weeks. Of these birthdays, births occurred on the following days: Monday Tuesday Wednesday Thursday Friday Saturday Sunday 163    125 155 142 131    101    115 Based on these data, test the hypothesis that babies are equally likely to be born on any given day. a. State a potential null and alternative hypothesis. What statistical test would be good to use? b. Test this data...
Randomly selected birth records were​ obtained, and categorized as listed in the table to the right....
Randomly selected birth records were​ obtained, and categorized as listed in the table to the right. Use a 0.01 significance level to test the reasonable claim that births occur with equal frequency on the different days of the week. How might the apparent lower frequencies on Saturday and Sunday be​ explained? Day Sunday Monday Tuesday Wednesday Thursday Friday Saturday Number of Births 50 58 65 64 59 56 35 Determine the null and alternative hypotheses: Calculate the test statistic X2...
Scheduling in the restaurant Workforce management is central to efficient operations and good customer service. Proper...
Scheduling in the restaurant Workforce management is central to efficient operations and good customer service. Proper scheduling of employees can mean the difference between profitability and business failure. After faithfully serving the OM profession for 40 years, you decide to retire and open a restaurant. Among the hundreds of details with opening a restaurant, you need to hire and schedule employees. Based on the foot traffic of other restaurants in the area, you expect that you will need the following...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT