我如何使用 for / foreach 循环实现上述结果 [图 2]?我用谷歌搜索但找不到我想要的答案......
$name = array('D1','D2','D3' );
foreach ( $name as $k=> $v ) {
$openTime3 = strtotime('10:00');
$closeTime3 = strtotime('15:00');
echo '<div class="col"> <span class="header">'.$v.'</span>';
while ( $openTime3 < $closeTime3 ) {
if ( ( date('Hi', $openTime3) > '1030' && date('Hi', $openTime3) < '1130' ) && $k == 1) {
echo '<span class="body "><a href="#" class="unconfirmed">B</a></span>';
break; /* ???? */
// try to use continue or break, and it didnt work i above result.
} else {
echo '<span class="body"><a href="#" class="available">AV</a></span>';
}
$openTime3 = strtotime('+15 minutes', $openTime3);
}
echo '</div>';
}
CSS代码:
.col { text-align: center; width: auto; float: left; }
.col > span { display: block; }
.col > span > a {height: 26px;line-height: 26px;display: block; padding: 0 10px; }
.col > span > .available { background: #D6F2F4; }
上面的代码总是返回下面的结果[图1]: