28

What does the following code do? A link to something in the PHP manual would also be nice.

if ($_SERVER['SERVER_PORT'] <> 443) {
    doSomething();
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ocergynohtna
  • 1,703
  • 2
  • 21
  • 29

6 Answers6

34

Same as !=, "Not equal"

false <> true // operator will evaluate expression as true
false != true // operator will evaluate expression as true

Here is some reference: PHP Comparison Operators

Kzqai
  • 22,588
  • 25
  • 105
  • 137
Christian C. Salvadó
  • 807,428
  • 183
  • 922
  • 838
7

It's another way of saying "not equal to" (the != operator). I think of it as the "less than or greater than" operator which really just means "not equal to".

Paige Ruten
  • 172,675
  • 36
  • 177
  • 197
5

It's equivalent to !=:

http://au.php.net/operators.comparison

​​​​​​

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
C. Broadbent
  • 753
  • 4
  • 11
2

$_SERVER['SERVER_PORT'] gets the port used by the web server to serve HTTP requests. $_SERVER['SERVER_PORT'] <> 443 checks if the port is not equal to 443 (the default HTTPS port) and if not, invokes doSomething()

indyfromoz
  • 4,045
  • 26
  • 24
2

Note that <> behaves as != even where < and > are not obvious comparison operators (eg $str1 <> $str2).

eyelidlessness
  • 62,413
  • 11
  • 90
  • 94
  • Why < and > are not "obvious comparison operators" for strings? – PhiLho Oct 30 '08 at 06:46
  • What the hell do they compare? As far as I can tell, they compare the "value" (alphabetically, a < b) of the strings. I can't imagine a use case for that. – eyelidlessness Oct 30 '08 at 06:54
  • 2
    @PhiLho Strings are not often thought of as less than or greater than each other, unless you're comparing the length of the string. This is where most of the confusion arises. – orokusaki Feb 23 '10 at 18:50
  • @orokusaki: Really? I wonder how you sort strings then... – PhiLho Feb 24 '10 at 17:58
  • @PhiLho I'm speaking in respects to comparison operators, not sorting algorithms. – orokusaki Feb 25 '10 at 01:53
  • @orokusaki: well, AFAIK, sorting algorithms use comparison operators... – PhiLho Feb 25 '10 at 07:07
  • @orokusaki: Perhaps we are not talking of the same thing. The code: s1 = "Absolute" s2 = "Bazaar" print(s1 < s2) print(s1 == s2) print(s1 > s2) shows true, false, false in Lua, Python and with minor changes PHP, JavaScript and probably lot of other languages. – PhiLho Feb 25 '10 at 07:20
  • I think it comes from Delphi/Pascal. Actually I can see a lot of Delphi/Pascal solutions in PHP like function declarations, ord(), chr() "and" "or" logic operators etc. It seems to me PHP is 50% C and 50% Pascal. – Tom Jun 16 '17 at 14:27
2

Although PHP is mostly based on C-style syntax, this is one of the weird things that comes from the BASIC-style syntax world.

Needless to say, I'd just use != and be consistent with it, as <> is really never used.

Ram Sharma
  • 8,676
  • 7
  • 43
  • 56
Bob Somers
  • 7,266
  • 5
  • 42
  • 46