What does the following code do? A link to something in the PHP manual would also be nice.
if ($_SERVER['SERVER_PORT'] <> 443) {
doSomething();
}
What does the following code do? A link to something in the PHP manual would also be nice.
if ($_SERVER['SERVER_PORT'] <> 443) {
doSomething();
}
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
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".
$_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()
Note that <>
behaves as !=
even where <
and >
are not obvious comparison operators (eg $str1 <> $str2
).
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.