我编写了一个代码来排除两个日期之间的周末和节假日。但现在我想将假期包含在文件中并排除它们。
代码工作正常
<?php
$joiningdate= date_create($row['jdate']); // Fetching this from database
$tdate = date('Y-m-d');
$todaydate1=date_create($tdate);
$todaydate1->modify('+1 day');
$interval=date_diff($todaydate1,$joiningdate);
$days = $interval->days;
// creating an iterateable period of date (P1D equates to 1 day)
$period = new DatePeriod($joiningdate, new DateInterval('P1D'), $todaydate1);
// Storing holidays in a array to exclude
$holidays = array('2019-01-15','2019-01-26','2019-03-04','2019-05-01','2019-08-15','2019-09-02','2019-10-02','2019-09-08', '2019-11-01');
foreach($period as $dt) {
$curr = $dt->format('D');
// substract holidays
if (in_array($dt->format('Y-m-d'), $holidays)) {
$days--;
}
// substracting if Saturday or Sunday
if ($curr == 'Sat' || $curr == 'Sun') {
$days--;
}
}
echo $days;
?>
我得到了预期的输出。但现在我需要将假期数组添加到文件中并排除它们。
慕妹3242003
慕的地8271018