How can PHP be used to calculate working hours that span multiple days?
To calculate working hours that span multiple days in PHP, you can use the DateTime class to handle date and time calculations. Start by creating DateTime objects for the start and end dates and times. Then, calculate the total working hours by subtracting the start time from the end time and accounting for any non-working hours (e.g., weekends or holidays).
$start = new DateTime('2022-01-01 08:00:00');
$end = new DateTime('2022-01-03 17:00:00');
$interval = $start->diff($end);
$totalHours = $interval->days * 24 + $interval->h;
echo "Total working hours: " . $totalHours;