In the given PHP code snippet, what improvements could be made to make the discount calculation more efficient and maintainable?

The given code snippet calculates discounts based on various conditions using nested if statements, which can become complex and hard to maintain as more conditions are added. To improve efficiency and maintainability, we can use a more structured approach like using switch statements or creating a separate function for discount calculation based on specific criteria.

// Improved discount calculation using switch statements

$discount = 0;
$subtotal = 100;

switch ($userType) {
    case 'regular':
        $discount = 0.1;
        break;
    case 'premium':
        $discount = 0.2;
        break;
    default:
        $discount = 0;
}

if ($subtotal > 100) {
    $discount += 0.05;
}

$total = $subtotal - ($subtotal * $discount);
echo "Total after discount: $total";