2 回答
TA贡献1712条经验 获得超3个赞
对您的最简单的修改可能如下:
$timetable = [
'Monday' => [],
'Tuesday' => [],
'Wednesday' => [],
'Thursday' => [],
'Friday' => []
];
foreach ($rows as $row) {
$courseDay = $row['course_day'];
if (isset($timetable[$courseDay])) {
$timetable[$courseDay][] = $row;
}
}
首先创建索引作为工作日的时间表,然后如果工作日匹配则添加事件。它还允许您通过在时间表变量中添加或删除它们来限制您支持的日期。
TA贡献1786条经验 获得超11个赞
尝试这样做
foreach ($rows as $row) {
switch ($row['course_day']) {
case "Monday":
$timetable['Monday'][] = $row;
break;
case "Tuesday":
$timetable['Tuesday'][] = $row;
break;
case "Wednesday":
$timetable['Wednesday'][] = $row;
break;
case "Thursday":
$timetable['Thursday'][] = $row;
break;
case "Friday":
$timetable['Friday'][] = $row;
break;
}
}
- 2 回答
- 0 关注
- 90 浏览
添加回答
举报