我想爲我的網絡創建調度。我怎樣才能得到每週2天的時間表。例如:每週顯示星期一和星期五。這是我的代碼:Foreach兩個DatePeriod對象
$day_of_week = "Monday";
$step = 1;
$unit = 'W';
$start = new DateTime("");
$end = clone $start;
$start->modify($day_of_week); // Move to first occurrence
$end->add(new DateInterval('P7W')); // Move to 1 year from start
$interval = new DateInterval("P{$step}{$unit}");
$period = new DatePeriod($start, $interval, $end);
foreach ($period as $date) {
echo '<tr>';
echo '<td><a href="lihatAbsen.php?tanggal='.$date->format('d-m-Y').'&id='.$id_kuliah.'">'.$date->format('d M Y').'</td>';
}
$day_of_week2 = "Friday";
$start->modify($day_of_week2); // Move to first occurence
$period2 = new DatePeriod($start, $interval, $end);
foreach ($period2 as $date) {
echo '<td><a href="lihatAbsen.php?tanggal='.$date->format('d-m-Y').'&id='.$id_kuliah.'">'.$date->format('d M Y').'</td></tr>';
}
它的工作,但我想打印在同一行<tr></tr>
與$period
對象$period2
對象。如何做正確的循環?或者如何獲得2天/周的輸入天數?
您使用的是哪個版本的PHP?哦,+1使用克隆和DateInterval和DatePeriod。 – 2014-10-03 18:11:50