PHP 两个日期之间是否有周六周日
目标:两个日期之间如果存在周六周日,有几个周六周日就延长几天
1.两个日期之间有多少个周六周日
2.截止日期加上统计出来的天数
注:两个日期为时间戳
记录一下
public function weektimes()
{
$start_time = time();//当前日期时间戳
$endstime = $start_time + 86400 * 7;//当前日期往后7天
//是否有周六周日
$week_array = [7, 1, 2, 3, 4, 5, 6];
$i = 0;
while ($start_time <= $endstime) {
$now_time = date('Y-m-d', $start_time);
// 可根据自己想要的返回格式进行调整
$alltime[$i]['week'] = $week_array[date("w", strtotime($now_time))];
$start_time = strtotime('+1 day', $start_time);
$i++;
}
$list = [];
foreach ($alltime as $key => $value) {
//周六周日数组
if ($value['week'] >= 6) {
$list[] = $value['week'];
}
}
//周六周日有几天
if (count($list) > 0) {
$count = count($list) - 1;
$endtime = $endstime + 86400 * $count;
} else {
$endtime = $endstime;
}
return $endtime;
}