function getConsecutiveWorkDays($date){
    list($year,$month,$day) = explode('-',$date);
    $holidays = array('2022-12-19','2022-12-20','2022-12-21');
    $dates    = array();
    while(count($dates) < 3){
        $newDate = date('Y-m-d',mktime(0,0,0,$month,--$day,$year));
        if(date('N',strtotime($newDate)) < 6 && !in_array($newDate,$holidays))
            $dates[] = $newDate;
    }
    return array_reverse($dates);
}
print_r(getConsecutiveWorkDays('2022-12-22'));
 Array ( [0] => 2022-12-14 [1] => 2022-12-15 [2] => 2022-12-16 ) 

 
 
 
 
 
 
 
 
0 Comments