PHP 基础代码之 17 比较运算符 Comparison Operators
实战需求
比较运算符比较两个值,然后返回true或false。它们主要用于指定条件,这些条件是计算为真或假的表达式。
解决方案
$x = (2 == 3); // equal to (false)
$x = (2 != 3); // not equal to (true)
$x = (2 <> 3); // not equal to (alternative)
$x = (2 === 3); // identical (false)
$x = (2 !== 3); // not identical (true)
$x = (2 > 3); // false,greater than (false)
$x = (2 < 3); // less than (true)
$x = (2 >= 3); // greater than or equal to (false)
$x = (2 <= 3); // less than or equal to (true)
严格相等运算符===和 !用于比较类型和值。这些都是必要的,因为常规的“等于”