This is a collection of questions that come up every now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.
It used to be hard to find questions about operators and other syntax tokens.¹
The main idea is to have links to existing questions on Stack Overflow, so it's easier for us to reference them, not to copy over content from …
==和之间有什么区别===?
==比较究竟是如何运作的?===比较究竟是如何运作的?什么是有用的例子?
我看见
if($output !== false){
}
Run Code Online (Sandbox Code Playgroud)
这是一个带有两个等号的感叹号.
它几乎是不平等的.它有什么额外的意义吗?
我知道这!==也用于比较变量类型,而!=只比较值.
但我看到很多人!==在比较价值时会使用,例如:
$stuff = 'foo';
if($stuff !== 'foo') // do...
Run Code Online (Sandbox Code Playgroud)
他们这样做有什么理由吗?是!==快!=还是什么?
我知道这可能是一个简单的问题,但想知道每个人的意见.
PHP中的switch和IF函数有什么区别?我能看到的是"切换"功能使用"IF"功能的地方也适用于那里......如果我错了,请纠正我.
或两者之间的任何表现明智的区别?
可能重复:
PHP中的!==和!=之间有区别吗?
Javascript === vs ==:我使用哪个"相等"运算符是否重要?
在某些情况下,当检查不相等时,我看到使用 != 并且在某些地方我看到了!==.这有什么不同吗?
例:
var x = 10;
if (x != 10) {
//...
}
Run Code Online (Sandbox Code Playgroud)
和
if (x !== 10) {
//...
}
Run Code Online (Sandbox Code Playgroud)