What best practices should be followed when writing PHP code to avoid common errors like unexpected syntax errors?

To avoid common errors like unexpected syntax errors in PHP code, it is important to follow best practices such as proper indentation, using consistent naming conventions, and closing all parentheses, brackets, and quotes. Additionally, using an IDE with syntax highlighting and error checking can help identify and prevent syntax errors before running the code. Example PHP code snippet implementing these best practices:

<?php

// Proper indentation and consistent naming conventions
function calculateTotal($price, $quantity) {
    $total = $price * $quantity;
    return $total;
}

// Closing all parentheses, brackets, and quotes
$total = calculateTotal(10, 5);
echo "Total: " . $total;

?>