为什么这个不起作用,它应该标记今天的日期或今天之后最近的日期。例如,如果日期是
16-01-30
,则选择的日期将为 16-02-14
。
$date = ['16-01-14', '16-01-28', '16-02-14', '16-02-28'];
$currentdate = date('y-m-d');
echo $currentdate;
?>
<form>
<select>
<?php
foreach ($date as $i => $d) {
if ($currentdate >= $d && ($i == count($date)-1 || $currentdate < $date[$i+1])) {
$selected = "selected";
} else {
$selected = "";
}
list($year, $month, $day) = explode('-', $d);
echo "<option $selected>$month/$day/$year</option>";
}
?>
</select>
</form>
这就是你的答案
$dates = array('16-01-14','16-01-28','16-02-14','16-02-28');
$currentdate = date('y-m-d');
echo $currentdate;
?>
<form>
<select>
<?php
foreach ($dates as $i => $d) {
if ($currentdate >= $d && ($i == count($dates)-1 || $currentdate < $dates[$i+1])) {
$selected = "selected";
} else {
$selected = "";
}
list($year, $month, $day) = explode('-', $d);
echo "<option $selected>$month/$day/$year</option>";
}