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

To improve the readability of PHP code, it is essential to follow best practices for organizing and formatting the code. This includes using consistent indentation, meaningful variable names, commenting code sections, and following a coding style guide such as PSR-12. By organizing and formatting PHP code properly, it becomes easier for developers to understand, maintain, and collaborate on the codebase.

<?php

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

$totalPrice = calculateTotal(50, 3);
echo "Total price: $totalPrice";

?>