How can PHP be used to calculate the next weekday based on a given date input?

To calculate the next weekday based on a given date input in PHP, you can use the `DateTime` class to manipulate the date and determine the next weekday. You can get the day of the week from the input date, calculate the number of days to add to reach the next weekday, and then add those days to the input date to get the next weekday.

$date = new DateTime('2022-01-15');
$dayOfWeek = $date->format('N'); // Get the day of the week (1 = Monday, 7 = Sunday)

$daysToAdd = ($dayOfWeek >= 5) ? (8 - $dayOfWeek) : (5 - $dayOfWeek); // Calculate days to add to reach the next weekday (Monday to Friday)

$date->modify("+$daysToAdd day"); // Add the days to the input date to get the next weekday

echo $date->format('Y-m-d'); // Output the next weekday