【发布时间】:2015-01-08 11:21:06
【问题描述】:
嘿,所以我在这里要做的是验证我的函数的两个来源是否设置了 $this->post["search"] 使用它或者是否设置了 $this->post["id"]使用 id,但不能同时使用:
($this->post["search"] or $this->post["id"])
如果我转储我得到一个布尔值,答案是正确的,为什么?
因此,如果我有一个像 sql 字符串这样的长字符串,我不想使用elseif,我想更像:
$this->sql->cell("select search_for('" . $this->post["search"] or $this->post["id"] . "') as response;");
【问题讨论】:
-
($this->post["search"] or $this->post["id"]) 返回 true 或 false 而不是比后数组元素的内容。即如果 $this->post["search"] 包含“找到我”,那么它是 true。
-
我想像问题一样在一行中使用,但似乎我需要使用 if/else
-
($this->post["search"]?$this->post["search"] : $this->post["id"])如果至少提供了一个值,则返回任一值。 Using the PHP Ternary Operator
标签: php debugging logical-operators