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.
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...
How would I structure the following PHP (PDO) code into a table format using only PHP?...
How would I structure the following PHP (PDO) code into a table format using only PHP? //Our SQL statement, which will select a list of tables from the current MySQL database. $sql = "SELECT * FROM jobs"; //Prepare our SQL statement, $statement = $pdo->prepare($sql); //Execute the statement. $statement->execute(); //Fetch the rows from our statement. $tables = $statement->fetchAll(PDO::FETCH_NUM); //Loop through our table names. foreach($tables as $table){ //Print the table name out onto the page. echo $table[0], ' '; echo $table[1], '...
Given the list values = [], write code that fills the list with each set of...
Given the list values = [], write code that fills the list with each set of numbers below. Note: use loops if it is necessary 1 2 3 4 5 6 7 8 9 10 0 2 4 6 8 10 12 14 16 18 20 1 4 9 16 25 36 49 64 81 100 0 0 0 0 0 0 0 0 0 0 1 4 9 16 9 7 4 9 11 0 1 0 1 0...
Write a log-in log-out session using PHP, CSS, and HTML only. NO MYSQL and JavaScript allowed....
Write a log-in log-out session using PHP, CSS, and HTML only. NO MYSQL and JavaScript allowed. 1. Need an HTML form and a login form; separate file. 2. need a CSS file to make it look good 3. Must store visitors' info in a .txt file and validate from there if the user exists before granting access to the dashboard. If the user does not exist, render the form to signup. If the user exists take them to their dashboard....
Multiple Part question: A) List the three forces determining the rate of glomerular filtration (write out...
Multiple Part question: A) List the three forces determining the rate of glomerular filtration (write out their full names) B) under each one, note the materials that are moving through the membrane (be specific) C) under each one, note which from which compartment to which compartment these materials are moving
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT