Question

In: Computer Science

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

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.

Solutions

Expert Solution

Code

<?php

$now = new \DateTime('now');//get todays data
$month = $now->format('m');//get current month
$year = $now->format('Y');//get current year
$days_in_months=[31,28,31,30,31,30,31,31,30,31,30,31];

//assosiative array that holds the days name and date where this days comes in this month
$days = [
'Monday' => [],
'Tuesday' => [],
'Wednesday' => [],
   'Thursday'=>[],
   'Friday'=>[],
   'Saturday'=>[],
   'Sunday'=>[],
];

for($i=1;$i<$days_in_months[$month-1];$i++)
{
   $date = $i.'-'.$month.'-'.$year;
   $nameOfDay = date('l', strtotime($date));
   if($nameOfDay=="Monday")
       array_push($days['Monday'], $i);
   elseif ($nameOfDay=="Tuesday")
       array_push($days['Tuesday'], $i);
   elseif ($nameOfDay=="Wednesday")
       array_push($days['Wednesday'], $i);
   elseif ($nameOfDay=="Thursday")
       array_push($days['Thursday'], $i);
   elseif ($nameOfDay=="Friday")
       array_push($days['Friday'], $i);
   elseif ($nameOfDay=="Saturday")
       array_push($days['Saturday'], $i);
   else
       array_push($days['Sunday'], $i);
}
echo date('F Y')."</br>";
foreach($days as $x => $x_value)
{
   echo "<b>$x:</b>";
   $i=0;
   for(;$i<count($x_value)-1;$i++)
       echo $x_value[$i].", ";
   echo $x_value[$i]."</br>";
}

?>

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.


Related Solutions

Write a PHP Program to display all the $_SERVER elements
Write a PHP Program to display all the $_SERVER elements
PHTHON 3 Write code that generates a list of the names of all the senders of...
PHTHON 3 Write code that generates a list of the names of all the senders of the messages in fb_data. Store it in a variable called senders. fb_data = { "data": [ { "id": "2253324325325123432madeup", "from": { "id": "23243152523425madeup", "name": "Jane Smith" }, "to": { "data": [ { "name": "Your Facebook Group", "id": "432542543635453245madeup" } ] }, "message": "Understand. Extract. Repeat.", "type": "status", "created_time": "2014-10-03T02:07:19+0000", "updated_time": "2014-10-03T02:07:19+0000" }, { "id": "2359739457974250975madeup", "from": { "id": "4363684063madeup", "name": "John Smythe" }, "to":...
Write and run the SQL to list the different expected graduation dates [class of 20XX] in...
Write and run the SQL to list the different expected graduation dates [class of 20XX] in the BSU_Students table. List each expected graduation date only once.  
List all of the ways in which the current tax code treats capital gains more favorably...
List all of the ways in which the current tax code treats capital gains more favorably than wage income.
PYTHON    Generates a list of datetimes given a list of dates and a list of...
PYTHON    Generates a list of datetimes given a list of dates and a list of times. All possible combinations of date and time are contained within the result. The result is sorted in chronological order. For example, Input: >>> timetable([date(2019,9,27), date(2019,9,30)], [time(14,10), time(10,30)]) Output: [datetime(2019,9,27,10,30), datetime(2019,9,27,14,10), datetime(2019,9,30,10,30), datetime(2019,9,30,14,10)] Current code: from datetime import date, time, datetime def timetable(dates, times): lis = []    for c in times: for y in dates: x = f"(datetime{y},{c})" lis.append(x) #doesn't work at all
Write shell script code that displays a list of all active processes in the system. Lift...
Write shell script code that displays a list of all active processes in the system. Lift the BSD-style “only yourself” restriction. The output should show the status of the processes. #!/bin/bash while [[ $REPLY != x ]]; do clear echo -e "Launch utilities:\n 1. Process Tree\n 2. Process States\n 3. Threads\n" read -p "Enter selection [1-3], or type x to exit: " REPLY if [ $REPLY == 1 ]; then    echo -e "\n"    #identify a command that displays...
Write a PHP script to display in frequency all the words in the submitted paragraph. Convert...
Write a PHP script to display in frequency all the words in the submitted paragraph. Convert the string to an array of words. Count the number of times the words are used. Hint: array_count_values($arrayname) Sort the array in frequency order. Print the array to the screen. Hint: print_r($arrayname)
write php code for buying and selling web using sql, javascript ,html ,css style
write php code for buying and selling web using sql, javascript ,html ,css style
Write a program in date_generator.py that generates all the dates of next year in mmm dd,...
Write a program in date_generator.py that generates all the dates of next year in mmm dd, yyyy format, as shown below. You need not calculate whether 2021 is a leap year--it is NOT. If you want to see a hint, scroll WAY down! Jan 1, 2021 Jan 2, 2021 Jan 3, 2021 . . . Dec 30, 2021 Dec 31, 2021 ***my teachers hint:My solution to this program is quite short, but the code is not super simple. I used...
C++ Question Write a code for :- public List Palindrome(); //Check whether a given singly linked...
C++ Question Write a code for :- public List Palindrome(); //Check whether a given singly linked list is palindrome or not. Input: a -> b-> NULL a -> b -> a-> NULL s -> a -> g -> a -> r-> NULL r -> a -> d -> a -> r-> NULL Output: not palindrome palindrome not palindrome palindrome Note:- Code should work on MS-Visual Studio 2017 and provide outputs with code
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT