What are some common pitfalls when working with if-else statements in PHP and how can they be avoided?

One common pitfall when working with if-else statements in PHP is forgetting to use curly braces {} for multiple lines of code within the if or else block. This can lead to unexpected behavior and errors in your code. To avoid this, always use curly braces even for single-line statements within if or else blocks.

// Incorrect way without curly braces
if ($condition)
    echo "Condition is true";
    echo "This will always be executed";

// Correct way with curly braces
if ($condition) {
    echo "Condition is true";
    echo "This will only be executed if the condition is true";
}