What are some best practices for refactoring PHP code to improve functionality and readability?

Issue: Refactoring PHP code is essential to improve functionality and readability. Some best practices include breaking down large chunks of code into smaller, more manageable functions, using meaningful variable names, removing redundant code, and following coding standards such as PSR-2. Code snippet:

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

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