Is there a recommended approach or script for managing bookings with overlapping seasonal pricing in PHP?

When managing bookings with overlapping seasonal pricing in PHP, one approach is to create a function that checks for overlapping dates and adjusts the pricing accordingly. This can be achieved by creating an array of seasonal pricing ranges and iterating through them to find the appropriate pricing for the booking dates.

function calculatePrice($bookingStartDate, $bookingEndDate) {
    $seasonalPricing = [
        ['start' => '2022-01-01', 'end' => '2022-03-31', 'price' => 100],
        ['start' => '2022-04-01', 'end' => '2022-06-30', 'price' => 150],
        ['start' => '2022-07-01', 'end' => '2022-09-30', 'price' => 200],
        ['start' => '2022-10-01', 'end' => '2022-12-31', 'price' => 120]
    ];

    $totalPrice = 0;

    foreach ($seasonalPricing as $season) {
        $start = max($bookingStartDate, $season['start']);
        $end = min($bookingEndDate, $season['end']);

        if ($start < $end) {
            $days = (strtotime($end) - strtotime($start)) / (60 * 60 * 24);
            $totalPrice += $days * $season['price'];
        }
    }

    return $totalPrice;
}

// Example usage
$bookingStartDate = '2022-05-15';
$bookingEndDate = '2022-06-15';

echo calculatePrice($bookingStartDate, $bookingEndDate);