How can one exclude specific weekdays, such as Saturdays, when counting the number of weekdays between two dates in PHP?

To exclude specific weekdays, such as Saturdays, when counting the number of weekdays between two dates in PHP, you can iterate through each day between the two dates and check if the day is not a Saturday before incrementing a counter for weekdays. This can be achieved by using the `DateTime` class in PHP to handle date calculations and comparisons.

$startDate = new DateTime('2022-01-01');
$endDate = new DateTime('2022-01-31');

$weekdays = 0;

while ($startDate <= $endDate) {
    if ($startDate->format('N') != 6) { // Check if the day is not Saturday (6)
        $weekdays++;
    }
    $startDate->modify('+1 day');
}

echo "Number of weekdays (excluding Saturdays) between the two dates: " . $weekdays;