What are some common pitfalls when using if-else statements for comparison in PHP?

One common pitfall when using if-else statements for comparison in PHP is not using strict comparison operators (=== and !==) which can lead to unexpected results due to PHP's loose type comparison rules. To avoid this, always use strict comparison operators to compare both value and type.

// Incorrect comparison without strict comparison operators
$value = '1';

if($value == 1){
    echo "Equal";
} else {
    echo "Not equal";
}

// Correct comparison using strict comparison operators
$value = '1';

if($value === 1){
    echo "Equal";
} else {
    echo "Not equal";
}