What are common pitfalls when using if statements in PHP for conditional logic?

One common pitfall when using if statements in PHP for conditional logic is forgetting to use the double equals sign (==) for comparison instead of a single equals sign (=), which is used for assignment. This mistake can lead to unintended consequences and logical errors in your code. To avoid this issue, always double-check your if conditions to ensure you are comparing values correctly.

// Incorrect usage of if statement with assignment instead of comparison
$number = 5;
if($number = 10) {
    echo "Number is 10";
} else {
    echo "Number is not 10";
}

// Corrected usage of if statement with double equals sign for comparison
$number = 5;
if($number == 10) {
    echo "Number is 10";
} else {
    echo "Number is not 10";
}