PHP 为什么这个 && 语句不会触发 false?
phpserver side programmingprogramming更新于 2025/8/17 3:52:17
这是因为,如果使用 && 语句,两个条件都必须为真。只要其中一个条件为假,整个条件就为假。
PHP 代码如下 −
示例
<!DOCTYPE html>
<html>
<body>
<?php
$firstCondition= "John";
$secondCondition = "David";
if ($firstCondition == "John" && $secondCondition == "David" && ($firstCondition == "Mike" || $firstCondition == "John")) {
echo "The above condition is true";
} else {
echo "The above condition is not true";
}
?>
</body>
</html>
输出
The above condition is true

