What are common mistakes when using if statements in PHP?

One common mistake when using if statements in PHP is forgetting to use double equals (==) for comparison instead of a single equals sign (=) which is used for assignment. This can lead to unintended behavior or errors in your code. To avoid this mistake, always double-check your if conditions to ensure you are using the correct comparison operator.

// Incorrect: using single equals sign for comparison
$number = 5;
if($number = 5){
    echo "Number is 5";
}

// Correct: using double equals sign for comparison
$number = 5;
if($number == 5){
    echo "Number is 5";
}