[英]I can't figure out php syntax
我这里需要分类法,
if ( $the_tax->name == 'day' , 'drink_type') {
$tax_output = '';
}
return $tax_output;
}
上面的代码写错了,白天的分类法,我不知道如何引用Drink_type的第二个分类法。 我用逗号吗? 或|| 或什么()如果有人知道php语法并可以提供帮助!
您需要逻辑OR
(可以用||
(通用语法)编写,也可以仅是OR
(特定于PHP),所以我不建议您使用)-有关更多详细信息, 请参阅逻辑运算符doc 。因此,您的代码应如下所示:
if( ($the_tax->name == 'day') || ($the_tax->name == 'drink_type') ) {
// at least one condition met
}
或使用in_array()来获得更多允许的名称:
$names = ['day','drink_type'];
if( in_array($the_tax->name, $names) {
// allowed name...
}
用||
分隔条件 (逻辑或)
if ( $the_tax->name == 'day' || $the_tax->name == 'drink_type') {
$tax_output = '';
}
return $tax_output;
}
根据您所说的,正确的语法为:
if ( $the_tax->name == 'day' || $the_tax->name == 'drink_type') {
// Note that you can't use id ($var == 'X' || 'Y')
正确的语法在if语句的两个条件之间使用两个管道。 像这样,
$tax_output;
if ( $the_tax->name == 'day' || $the_tax->name == 'drink_type') {
$tax_output = '';
}
return $tax_output;
我省略了您的结尾}
因为这样会引发语法错误。 如果应该在该结尾处加上括号,则还应添加代码中包含开头括号的部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.