PHP operator <> [duplicate]

人盡茶涼 提交于 2019-12-19 05:02:09

问题


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

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

回答1:


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




回答2:


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




回答3:


It's equivalent to !=:

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

​​​​​​




回答4:


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




回答5:


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




回答6:


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.



来源:https://stackoverflow.com/questions/249312/php-operator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!