What is the best practice for generating an array of weekend dates in a specific month and year using PHP?

To generate an array of weekend dates in a specific month and year using PHP, you can loop through all the days in the month and check if each day falls on a weekend (Saturday or Sunday). If a day is a weekend, add it to the array of weekend dates.

function getWeekendDates($month, $year) {
    $weekendDates = [];

    $daysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);

    for ($day = 1; $day <= $daysInMonth; $day++) {
        $date = date('Y-m-d', strtotime("$year-$month-$day"));
        $dayOfWeek = date('N', strtotime($date));

        if ($dayOfWeek == 6 || $dayOfWeek == 7) {
            $weekendDates[] = $date;
        }
    }

    return $weekendDates;
}

$month = 10;
$year = 2022;
$weekendDates = getWeekendDates($month, $year);

print_r($weekendDates);