$course_hour = 1; $starttime = '07:00'; $endtime = '16:00';
I want it to return an array of values like this: if
$course_hour = 1;
$return_array = array('07:00 - 08:00', '08:00 - 09:00', '09:00 - 10:00', '10:00 - 11:00', '11 :00 - 12:00', '12:00 - 13:00', '13:00 - 14:00', '14:00 - 15:00', '15:00 - 16:00'); if
$course_hour = 1.5;
$return_array = array('07:00 - 08:30', '8:30 - 10:00', '10:00 - 11:30', '11:30 - 13:00', '13 :00 - 14:30', '14:30 - 16:00'); if
$course_hour = 2;
$return_array = array('07:00 - 09:00', '09:00 - 11:00', '11:00 - 13:00', '13:00 - 15:00');< /p>
function get_session_times($course_hour, $start_time, $end_time){ if(strlen($start_time) < 5) $start_time = '0'.$start_time; if(strlen($end_time) < 5) $end_time = '0'.$end_time; $current_time = date("Y-m-d H:i"); $session_starttime = date("Y-m-d H:i", strtotime(date("Y-m-d ").$start_time)); $session_endtime = date("Y-m-d H:i", strtotime(date("Y-m-d ").$end_time)); $session_starttime_ms = strtotime($session_starttime); $session_endtime_ms = strtotime($session_endtime); $session_times_array = array(); for ($i = $session_starttime_ms; $i < $session_endtime_ms; ) { $session_times_array[] = date("H:i", $i)."<br/>"; $i = $i + ($course_hour * 60 * 60); } return $session_times_array; }
You must convert to hours and minutes according to 1,
1.5
). com/a/27497314/128761">This answer.Then I used the code in this answer mentioned by mickmackusa to get the time array.
This is a test.
The result will be...