1. 拆分
$start = '08:30'; $end = '20:00'; $arr = []; for ($i = strtotime($start); $i <= strtotime($end); $i = $i + 60 * 30) { $arr[] = date("H:i", $i); } print_r($arr);
2. 组合
$result = []; $num = count($arr); foreach ($arr as $key => $val) { if ($key < $num) { $time_str = strtotime($val); $result[] = array( 'start_time' => $val, 'end_time' => date('H:i', $time_str + 60 * 30) ); } } print_r($result);