What are the best practices for formatting PHP code to improve readability and maintainability?

To improve the readability and maintainability of PHP code, it is important to follow certain best practices such as using consistent indentation, meaningful variable names, and comments to explain complex logic. Additionally, breaking down large chunks of code into smaller, modular functions can make the code easier to understand and maintain.

<?php

// Example of well-formatted PHP code
function calculateTotal($prices) {
    $total = 0;

    foreach ($prices as $price) {
        $total += $price;
    }

    return $total;
}

$prices = [10, 20, 30];
$total = calculateTotal($prices);
echo "The total is: " . $total;

?>