I have to make a little script for a school assignment which places the days of the week in chronological order with an index in front of them. Although Sunday has to be the first day and therefore must have the number 1 in front of it. (2 Monday, 3 Tuesday etc.)
I have tried to do this by placing all the elements in the array one index further but it does not seem to work.
$myArray = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
for ($i=0; $i<count($myArray); $i++) {
$myArray[$i] = $myArray[$i+1];
echo ($i+1) . " " . $myArray[$i] . "<br>";
}
And here is the error message i get when i execute the code:
1 Tuesday
2 Wednesday
3 Thursday
4 Friday
5 Saturday
6 Sunday
Notice: Undefined offset: 7 in C:\xampp\htdocs\opdracht_22.php on line 13
7
The result i am trying to get is:
1 Sunday
2 Monday
3 Tuesday
4 Wednesday
5 Thursday
6 Friday
7 Saturday
Is there anything i am missing here? How can i improve my code?