如何让这一天变成浅红色。其他日子都是绿色的。我尝试过类似的东西,但缺少一些东西。有人可以帮忙吗? 如果您阅读以下代码,您将了解我想要做什么。我错过了一部分,但我不知道哪部分。请帮我。
<table border="1">
<?php
date_default_timezone_set('Europe/Stockholm');
echo"<tr>";
$week_number = 21;
$year = 2018;
if($week_number < 10){
$week_number = "0".$week_number;
}
for($day=1; $day<=7; $day++)
{
$days[$day] = date('d', strtotime($year."W".$week_number.$day))."\n";
$daysnumber=$days[$day];
$today=date('d');
if ($daysnumber>=$today){
echo"<td bgcolor='red'>$daysnumber</td>" ;
}
else
{
if ($daysnumber<=$today){
echo"<td bgcolor='green'>$daysnumber</td>" ;
}
else
{
}
}}
?>
</table>
答案 0 :(得分:3)
<table border="1">
<?php
date_default_timezone_set('Europe/Stockholm');
echo"<tr>";
$week_number = 21;
$year = 2018;
if($week_number < 10):
$week_number = "0".$week_number;
endif;
for($day = 1; $day <= 7; $day++):
$daysnumber = date('d', strtotime($year."W".$week_number.$day));
$today = date('d');
if($daysnumber == $today):
echo "<td bgcolor='red'>$daysnumber</td>";
else:
echo "<td bgcolor='green'>$daysnumber</td>" ;
endif;
endfor;
?>
</table>
你在这里犯了错误:
$days[$day] = date('d', strtotime($year."W".$week_number.$day))."\n";
\n
在$days[$day]
中添加了空格,因为它无法与之比较
'22 ' == '22'