Write a PHP script to display array elements as follows. Create an array that co
ID: 3680245 • Letter: W
Question
Write a PHP script to display array elements as follows.
Create an array that contains the names of the days of the week; i.e., Monday, Tuesday, etc.
Display the entire content of the array using a loop.
Display the element and index number for the current day of the week. Use the date functions/objects to identify the current day of the week.
Display the element and index number for the day of the week that will occur in 4 days. Check that you don't go past the end of the array. If so, continue counting days starting at the beginning of the array.
Explanation / Answer
php script:
<html>
<body>
<?php
/* Second method to create array. */
$numbers[0] = "Sunday";
$numbers[1] = "Monday";
$numbers[2] = "Tuesday";
$numbers[3] = "Wednessday";
$numbers[4] = "Thrusday";
$numbers[5] = "Friday";
$numbers[6] = "Saturday";
foreach( $numbers as $value ) {
echo " $value <br />";
}
$i=0;
foreach( $numbers as $value ) {
if($value==date("l"))
{
echo "today day of the week is:$value with index number:$i<br/>";
$four=($i+4)%7;
echo "day of the week after four days is $numbers[$four] with index number:$four<br/>";
}
$i=$i+1;
}
?>
</body>
</html>
output:
Sunday
Monday
Tuesday
Wednessday
Thrusday
Friday
Saturday
today day of the week is:Tuesday with index number:2
day of the week after four days is Saturday with index number:6
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.