views:

330

answers:

7
+5  Q: 

php operator <>

can someone explain this one to me? a link to something in the php manual even?? i can't find anything:

if ($_SERVER['SERVER_PORT'] <> 443) {
    doSomething();
}
+12  A: 

Same that !=, Not equal

$a <> $b

Here is some reference: PHP Comparison Operators

CMS
Beaten by 2 seconds!
PlacidBox
+2  A: 

It's equivelent to !=

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

PlacidBox
+2  A: 

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

yjerem
+1  A: 

$_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
A: 

good show! thanks to all that answered. :) loving stack overflow. :P

ocergynohtna
I understand your enthusiasm, but it's discouraged to post an answer to your own question (or any question) that's not an answer, but a comment. If you wish to compliment someone for a good answer, upvote, give a positive comment, or (best of all) accept their answer as correct. See the FAQ (http://stackoverflow.com/faq) for more information. Not trying to get on your back or anything, just trying to encourage you in what this site considers the "right direction." :)
Chris Lutz
+1  A: 

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

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

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.

Bob Somers