What are best practices for formatting and organizing PHP code to avoid errors?

To avoid errors in PHP code, it is important to follow best practices for formatting and organizing code. This includes using consistent indentation, clear and descriptive variable names, commenting code for clarity, and following a coding style guide such as PSR-12.

<?php

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

$price = 10;
$quantity = 5;
$total = calculateTotal($price, $quantity);

echo "Total: $total";

?>