我正在創建一個小預訂系統。行被設置爲當前周的列到特定時間。如果語句在foreach循環中
我想要做的是將日期名稱更改爲特定的顏色。藍色在過去,日期目前在綠色。不知何故if
聲明沒有做任何事情。任何人都可以向正確的方向解釋或指出我嗎?
$today = time();
$lastWeek = [];
$lastWeek[0] = date('D',strtotime('last monday'));
$lastWeek[1] = date('D',strtotime('last monday +1day'));
$lastWeek[2] = date('D',strtotime('last monday +2day'));
$lastWeek[3] = date('D',strtotime('last monday +3day'));
$lastWeek[4] = date('D',strtotime('last monday +4day'));
$timeSlot = [];
$timeSlot [0] = date('H:i', strtotime('9:00')) ."-9:30";
$timeSlot [1] = date('H:i', strtotime('9:30')) ."-10:00";
$timeSlot [2] = date('H:i', strtotime('10:00')) ."-10:30";
$timeSlot [3] = date('H:i', strtotime('10:30')) ."-11:00";
$timeSlot [4] = date('H:i', strtotime('11:00')) ."-11:30";
$timeSlot [5] = date('H:i', strtotime('11:30')) ."-12:00";
echo "<html><head><title>Doctor Booking timetable</title></head>";
echo "<body><table id=myTable border=2 align=center >";
echo "<tr><td>Week Commencing</td>";
foreach ($timeSlot as $time)
{
echo"<td>";
echo $time;
echo"</td>";
}
echo "</tr>";
foreach ($lastWeek as $day)
{
echo "<tr><td>";
echo $day;
echo "</td></tr>";
}
if ($lastWeek < $today){
echo "<font color='blue'></font>";
}else {
echo "<font color='green'></font>";
}
的'if'語句是*不*了'foreach'循環中。 – Boaz
你也需要查看一些HTML教程,你的html無效。 '$ lastWeek'是一個數組,它不會評估爲真 –
foreach循環中if語句的語法是什麼?出現了很多錯誤。謝謝。 – user3204192