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

To improve readability of PHP code, it is important to follow best practices for formatting and organizing the code. This includes using consistent indentation, clear and descriptive variable names, and commenting code where necessary. Additionally, breaking down code into smaller, logical sections and using whitespace to separate different parts of the code can also help improve readability.

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

    // Apply discount if total is above a certain amount
    if ($total > 100) {
        $discount = $total * 0.1;
        $total -= $discount;
    }

    return $total;
}