How can proper formatting and indentation of PHP code improve readability and maintenance?
Proper formatting and indentation of PHP code can greatly improve readability and maintenance by making the code easier to understand and navigate. It helps in identifying logical blocks of code, making it easier to spot errors and debug issues. Consistent indentation also makes it easier for multiple developers to collaborate on the same codebase.
<?php
// Badly formatted code
function calculateTotal($price, $quantity){
$total=$price*$quantity;
return $total;
}
// Properly formatted code
function calculateTotal($price, $quantity) {
$total = $price * $quantity;
return $total;
}
?>