我想为我的网络创建调度。我怎样才能得到每周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