27
votes

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

if ($_SERVER['SERVER_PORT'] <> 443) {
    doSomething();
}
6

6 Answers

33
votes

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

7
votes

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".

5
votes
2
votes

$_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()

2
votes

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

2
votes

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.