29

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

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

6 Answers 6

35

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

Sign up to request clarification or add additional context in comments.

Comments

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

2 Comments

It is equivalent to saying: Less than AND greater than.
@RobFarr I don't think so. Nothing can be less than and greater than.
5

It's equivalent to !=:

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

​​​​​​

Comments

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

Comments

2

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

8 Comments

Why < and > are not "obvious comparison operators" for strings?
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.
@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: Really? I wonder how you sort strings then...
@PhiLho I'm speaking in respects to comparison operators, not sorting algorithms.
|
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.