What are the best practices for formatting PHP code to ensure readability and maintainability?

To ensure readability and maintainability of PHP code, it is important to follow consistent formatting practices such as using proper indentation, spacing, and naming conventions. Additionally, utilizing comments to explain complex logic or functionality can greatly improve code readability for yourself and other developers.

<?php

// Example of properly formatted PHP code
function calculateSum($num1, $num2) {
    // Calculate the sum of two numbers
    $sum = $num1 + $num2;

    return $sum;
}

// Call the function and output the result
$result = calculateSum(5, 10);
echo "The sum is: " . $result;

?>