Answer the question
In order to leave comments, you need to log in
How to add missing elements to PHP array?
Hello! There is an array with data for the class schedule. Each element is an array with the name of the day and the time span. Since classes are not every day, there are no elements with some days (For example, classes are on Mon, Wed, Fri). The idea is to add elements to the array with the name of the day (without time), so that the days always go in order from Monday to Saturday, and even if the first day is Tuesday, or Wednesday could be formatted to start with Monday.
array:6 [▼
0 => array:2 [▼
"day" => "Monday"
"time" => "14:30-15.50"
]
1 => array:2 [▼
"day" => "Wednesday"
"time" => "14:30-15.50"
"time" => "14:30-15.50"
]
3 => array:2 [▼
"day" => "Monday"
"time" => "17:30-18:20"
]
4 => array:2 [▼
"day" => "Wednesday"
"time" => "17:30 -18:20"
]
5 => array:2 [▼
"day" => "Friday"
"time" => "17:30 –18:20"
]
]
Answer the question
In order to leave comments, you need to log in
1. add missing days: foreach ... if (!isset...) add.
2. sort by days of the week: usort
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question