📜  $a != $b 和 $a !== $b 之间的区别

📅  最后修改于: 2022-05-13 01:56:41.147000             🧑  作者: Mango

$a != $b 和 $a !== $b 之间的区别

$a!=$b

该运算符也称为不等式运算符。它用于检查两个操作数的相等性,但是,操作数的类型不匹配。例如,如果两个操作数的值相同,则整数类型变量等效于浮点数。它是一个二元运算符。

PHP


PHP


PHP


输出
Both operands are Equal

$a!==$b

这是非恒等运算符。它用于检查两个操作数的相等性,但是,操作数的类型也匹配。例如,无论两个操作数的值如何,整数类型变量都不等于浮点数。它是一个二元运算符。

PHP


输出
Both operands are not same

!= 和 !==运算符之间的区别:

!=

!==

It returns true if value of both operands are equal.It returns true if value and and data type of both operands are equal.
It is known as Inequality Operator.It is known as Non-identity Operator.
Empty values are considered to be equivalent.Empty values should belong to same data type.

示例:以下代码片段以简单的方式说明了这两个运算符的区别。

PHP


输出
Both operands are equal (Only Value)
Both operands are not equal (Value and Data Types)