Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between "not equal" operators <> and != in PHP

Tags:

operators

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.

like image 663
Trufa Avatar asked Nov 27 '10 23:11

Trufa


People also ask

What is difference between != and <> operator in PHP?

==' operator checks the unequality of two objects with a type check. It does not converts the datatype and makes a typed check. For example 1 !== '1' will results true.

What does <> mean in PHP?

The spaceship operator <=> is the latest comparison operator added in PHP 7. It is a non-associative binary operator with the same precedence as equality operators ( == , !=

What is difference between <> and NOT operators?

Here is the answer – Technically there is no difference between != and <>. Both of them work the same way and there is absolutely no difference in terms of performance or result. Here is the follow up question I received right I answer that there is no difference between those operator.

Whats the difference between != and !==?

!= will only check value regardless of operands type. but !== is used to compare both value & type of 2 operands that are being compared to each other.


1 Answers

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 
like image 95
Vitalii Fedorenko Avatar answered Oct 02 '22 13:10

Vitalii Fedorenko