In the provided PHP code snippet, what are the best practices for formatting and spacing to ensure readability and maintainability?
To ensure readability and maintainability of PHP code, it is important to follow best practices for formatting and spacing. This includes using consistent indentation, proper spacing around operators and control structures, and adding comments to explain complex logic. By following these practices, code becomes easier to read, understand, and maintain.
<?php
// Example of properly formatted and spaced PHP code
function calculateTotal($price, $quantity) {
$total = $price * $quantity;
if ($total > 100) {
$discount = $total * 0.1;
$total -= $discount;
}
return $total;
}
?>