Skip to content
Advertisement

Difference between “not equal” operators and != in PHP

In PHP, is there any difference between the != and <> operators?

In the manual, it states:

$a != $b    Not equal   TRUE if $a is not equal to $b after type juggling.
$a <> $b    Not equal   TRUE if $a is not equal to $b after type juggling.

I guess there are no huge differences but I’m curious.

Advertisement

Answer

In the main Zend implementation there is not any difference. You can get it from the Flex description of the PHP language scanner:

<ST_IN_SCRIPTING>"!="|"<>" {
    return T_IS_NOT_EQUAL;
}

Where T_IS_NOT_EQUAL is the generated token. So the Bison parser does not distinguish between <> and != tokens and treats them equally:

%nonassoc T_IS_EQUAL T_IS_NOT_EQUAL T_IS_IDENTICAL T_IS_NOT_IDENTICAL
%nonassoc '<' T_IS_SMALLER_OR_EQUAL '>' T_IS_GREATER_OR_EQUAL
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement