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

One best practice for structuring and formatting PHP code is to use consistent indentation to improve readability. This helps to visually separate different code blocks and makes it easier to follow the flow of the code. Additionally, using meaningful variable names and comments can help improve maintainability by making the code easier to understand for other developers.

// Example of well-structured and formatted PHP code
function calculateTotal($price, $quantity) {
    $subtotal = $price * $quantity;
    
    // Apply a 10% discount if the subtotal is greater than $100
    if ($subtotal > 100) {
        $discount = $subtotal * 0.1;
        $total = $subtotal - $discount;
    } else {
        $total = $subtotal;
    }
    
    return $total;
}