Skip to content
PHP Logo

What is the correct syntax for comparing values in if statements in PHP?

When comparing values in if statements in PHP, you should use the double equals sign (==) for comparison, not the single equals sign (=) which is used for assignment. Using the incorrect syntax can lead to unexpected behavior in your code. Make sure to use the correct comparison operators such as == for equality, != for not equal, === for identical, and !== for not identical.

php
// Correct syntax for comparing values in if statements
$number = 10;

if ($number == 10) {
    echo "The number is 10";
}