php - Break time into multiple times -
let's have array multiple instance of class:
class booking { public $status; public $start_time; public $end_time; }
array[0] $status = true $start_time = 13:30 $end_time = 14:00
array[1] $status = true $start_time = 14:30 $end_time = 17:30
array[2] $status = true $start_time = 20:30 $end_time = 21:30
array[3] $status = true $start_time = 22:00 $end_time = 23:30
how elaborate function given time, 12:00
, 23:00
generate array, multiple instances of same class, although this:
array[0] $status = false $start_time = 12:00 $end_time = 13:30
array[1] $status = true $start_time = 13:30 $end_time = 14:00
array[2] $status = false $start_time = 14:00 $end_time = 14:30
array[3] $status = true $start_time = 14:30 $end_time = 17:30
array[4] $status = false $start_time = 17:30 $end_time = 20:30
array[5] $status = true $start_time = 20:30 $end_time = 21:30
array[6] $status = false $start_time = 21:30 $end_time = 22:00
array[7] $status = true $start_time = 22:00 $end_time = 23:00
look in direction:
function generate($from, $till) { $result = array(); $t = $from; $status = true; while($t <= $till) { $result[] = new booking($status, date('h:i', $t), date('h:i', $t+30*60)); $t = $t+30*60; $status = !$status; } return $result; }
Comments
Post a Comment