How can the formatting of code be improved to make it more readable and maintainable in PHP scripts, especially when posting on forums?

To improve the formatting of code in PHP scripts for better readability and maintainability, it is important to follow consistent indentation, use meaningful variable names, and add comments to explain complex logic. When posting code on forums, consider using code blocks or formatting options provided by the forum to make the code easier to read.

<?php

// Example of well-formatted PHP code
function calculateTotal($price, $quantity) {
    $total = $price * $quantity; // Calculate total price
    return $total; // Return the total
}

$price = 10;
$quantity = 5;
$total = calculateTotal($price, $quantity);
echo "Total: $" . $total;

?>