format('H:i'); //take hour and minute $i->modify("+60 minutes"); //add 20 minutes $time2 = $i->format('H:i'); //take hour and minute if ($i <= $end) //if not booked and less than end time { if ($time1 == '23:00') { $time2 = '24:00'; } $scope = $time1 . '-' . $time2; $slots = ['start' => $time1, 'stop' => $time2, 'scope' => $scope, 'status' => 0]; //add count array_push($out, $slots); //add slot to array } } return $out; } }