例如,如果我不想显示27.12,如何隐藏某些日期?当前它正在运行,以便此循环连续运行,无论我插入哪个查询,无论是否显示27,都将继续显示。我想插入一个数组,其中包含几个不应显示的日期。
$date = time() + (86400*3);
$b = 5; // Anzahl Schleifendurchläufe
$cb = "4";
for($i = 0; $i < $b; $i++) {
$cb++;
echo '<li><input type="checkbox" id="'.$cb.'" name="Datum" value="'.date('d.m.Y', $date).'"/>'.date('d.m.Y', $date).'
<label class="ort" for="'.$cb.'"><img src="https://www.tintencenter.com/blog/wp-content/uploads/2019/02/kalender-678x381.jpg" /><br><br></label>
</li>';
$date += 86400;
@RiggsFolly那正是我的想法,但是循环中不再显示任何内容,而不仅仅是这个日期。但是随后所有其他条目也不可见...我担心其他条目仍可见,只有特定日期不可见。或者它只是在循环中发生。
for($i = 0; $i < $b; $i++) {
$cb++;
if (date('d.m', $date) == '31.12'){
echo '<li><input type="checkbox" id="'.$cb.'" name="Datum" value="'.date('d.m.Y', $date).'"/>'.date('d.m.Y', $date).'
<label class="ort" for="'.$cb.'"><img src="https://www.tintencenter.com/blog/wp-content/uploads/2019/02/kalender-678x381.jpg" /><br><br></label>
</li>';
$date += 86400;
}else{
echo '<li><input type="checkbox" id="'.$cb.'" name="Datum" value="'.date('d.m.Y', $date).'"/>'.date('d.m.Y', $date).'
<label class="ort" for="'.$cb.'"><img src="https://www.tintencenter.com/blog/wp-content/uploads/2019/02/kalender-678x381.jpg" /><br><br></label>
</li>';
$date += 86400;
}
答案 0 :(得分:0)
一个简单的IF应该允许您不打印日期之一
$aDay = 86400*3;
$date = time() + $aDay;
$b = 5; // Anzahl Schleifendurchläufe
$cb = "4";
echo 'Loop without any checks'.PHP_EOL;
for($i = 0; $i < $b; $i++) {
echo date('d.m.Y',$date) . PHP_EOL;
$date += $aDay;
}
//reset date and pick one of the dates that will occur and stop it
$date = time() + $aDay;
echo PHP_EOL.'Loop with checks'.PHP_EOL;
for($i = 0; $i < $b; $i++) {
$cb++;
if (date('d.m', $date) == '07.01'){
echo 'Dont print it ' . date('d.m.Y', $date) . PHP_EOL;
}else{
echo 'Print it ' .date('d.m.Y', $date) . PHP_EOL;
}
$date += $aDay;
}
结果
Loop without any checks
01.01.2020
04.01.2020
07.01.2020
10.01.2020
13.01.2020
Loop with checks
Print it 01.01.2020
Print it 04.01.2020
Dont print it 07.01.2020
Print it 10.01.2020
Print it 13.01.2020