2

What does the <> operator mean exactly?

Is it the same as != (not equal)?

Sample code

$foo = 'text';

if ($foo <> 'photo') {
    echo 'foo';
}
else {
    echo 'bar';
}
Community
  • 1
  • 1
ocergynohtna
  • 1,667
  • 2
  • 20
  • 28

3 Answers3

13

As NikiC notes, <> and != are the same and have the same precedence. My earlier answer was based on what appears to be a bug in the documentation which has now been corrected.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Zoredache
  • 31,819
  • 7
  • 40
  • 59
  • This is actually not true. `<>` has the same precedence as `!=`. They even share the same token, so they are absolutely identical from the parser's point of view. Proof: http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_language_scanner.l#1364 – NikiC Sep 12 '12 at 17:55
  • @NikiC, You are right. There appears to have been a bug in the documentation, which I was using as my reference. The bug was corrected on Jul 17 2012. See: http://svn.php.net/viewvc/phpdoc/en/trunk/language/operators.xml?view=log and `svn diff --force -r 326293:326667 https://svn.php.net/repository/phpdoc/en/trunk/language/operators.xml` – Zoredache Sep 12 '12 at 19:08
  • I already suspected that this was the case. Thanks for fixing up the answer :) – NikiC Sep 12 '12 at 21:17
3

That would be correct. It's pretty universal between languages. I usually use that method in my SQL Server queries/stored procedures.

PHP: Comparison Operators

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
William Holroyd
  • 3,223
  • 1
  • 19
  • 25
1

Yes, it's the same as != (see the manual).

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Henrik Paul
  • 63,711
  • 30
  • 82
  • 93