php - 具有多个条件的 PHP if 语句
问题描述
以下 if 语句的有效语法如何?
if ($properties->offering_type === 'y' || $properties->offering_type === 'p' && $properties->sold != 'y') {
// echo something
} else {
}
我想什么echo something
时候offering_type
是y
或者不是p
sold
y
解决方案
&&
的优先级高于||
,因此您的条件被解释为
if ($properties->offering_type === 'y' ||
($properties->offering_type === 'p' && $properties->sold != 'y')) {
您需要添加括号将它们组合||
在一起。
if (($properties->offering_type === 'y' || $properties->offering_type === 'p')
&& $properties->sold != 'y') {
推荐阅读
- sqlite - 未找到 Apache Airflow 提供程序 Sqlite 模块/钩子“airflow.hooks.dbapi import DbApiHook”错误
- javascript - 看到错误 - “[match] query malformed, no start_object after query name”不知道为什么
- reactjs - 如何在 React JS 中隐藏/显示提交按钮
- oracle-cloud-infrastructure - Oracle 云基础设施 – 跨区域获得计算形态?
- sql-server - SSRS 表达式查询 - SQL Server 报表生成器
- php - 网页 PHP 中的永久网络播放器。Ajax 还是 Service Worker?
- javascript - mobile navbar not collapsing
- azure-ad-b2c - B2C 自定义策略 - 添加按钮以重定向到另一个自定义策略
- mysql - Mysql在之前/之后获取特定单词
- java - Android kotlin 中的夏令时