【发布时间】:2016-09-14 14:26:02
【问题描述】:
以下情况应该如何做switch case:
例如,案例 1 如下所示:
if($this->hasA() && $this->hasB() && $this->hasC() && $this->hasD())
{
# ....
}
案例 2 可能如下所示:
if($this->hasA() && $this->hasB())
{
# ....
}
函数返回一个布尔值。
这可能不是一个好习惯,但我想知道这在 switch 案例中会是什么样子。
【问题讨论】:
-
你必须重组你的函数以使它与开关盒一起工作,例如:
switch($this->retrieveABCD()) { case "A" } -
一个 switch 通常会有多个 case,你有 1 个。
-
@AbraCadaver 抱歉,我确实有多个案例,我会快速编辑问题
标签: php if-statement switch-statement conditional-statements