How does PHP handle lexical comparison when using the identity operator ===?

When using the identity operator === in PHP, lexical comparison is used to compare two variables. This means that not only the values of the variables are compared, but also their types. To handle lexical comparison correctly, make sure that the variables being compared have the same type. If necessary, use type casting to ensure that the variables are of the same type before using the identity operator.

$var1 = 10;
$var2 = '10';

// Using type casting to ensure both variables are integers
if ((int)$var1 === (int)$var2) {
    echo 'The variables are identical.';
} else {
    echo 'The variables are not identical.';
}