In what ways can the PHP code be refactored to follow better coding standards and improve readability?

Issue: The PHP code is difficult to read and does not follow coding standards, making it hard to maintain and understand. To improve readability and adhere to better coding practices, we can break down the code into smaller functions, use meaningful variable names, and properly indent the code. Refactored PHP code:

<?php

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

$cartItems = [
    ['name' => 'Item 1', 'price' => 10, 'quantity' => 2],
    ['name' => 'Item 2', 'price' => 20, 'quantity' => 1],
];

$total = calculateTotal($cartItems);
echo 'Total: $' . $total;

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

$cartItems = [
    ['name' => 'Item 1', 'price' => 10, 'quantity' => 2],
    ['name' => 'Item 2', 'price' => 20, 'quantity' => 1],
];

$total = calculateTotal($cartItems);
echo 'Total: $' . $total;