How can the code snippet be optimized for better readability and maintainability?

The code snippet can be optimized for better readability and maintainability by breaking down the logic into smaller, more understandable functions and using meaningful variable names. This will make the code easier to read, understand, and maintain in the future.

<?php

// Original code snippet
function calculateTotalPrice($items, $discount) {
    $total = 0;
    foreach ($items as $item) {
        $total += $item['price'];
    }
    $discountedTotal = $total * (1 - $discount);
    return $discountedTotal;
}

// Optimized code snippet
function calculateTotalPrice($items, $discount) {
    $total = calculateTotal($items);
    $discountedTotal = applyDiscount($total, $discount);
    return $discountedTotal;
}

function calculateTotal($items) {
    $total = 0;
    foreach ($items as $item) {
        $total += $item['price'];
    }
    return $total;
}

function applyDiscount($total, $discount) {
    return $total * (1 - $discount);
}

?>