【发布时间】:2014-11-07 19:04:23
【问题描述】:
在变量字符串中使用 IF/ELSE 语句的正确方法是什么?
例子:
$htmlOutput = 'The current color of the sky is ' .
if ($time==="day") { . 'blue.' . }
else if ($time==="night") { . 'black' . };
显然,该示例不起作用,但您可以看到我正在尝试做的事情。我知道我可以继续 if 语句中的变量,例如:
$htmlOutput .= '';
但我很好奇是否有如上所述的方法。
【问题讨论】:
-
避免在三元运算中做任何比单个
if x then y else z更复杂的事情。它们可以嵌套,但很快就会变得非常不可读。(if x then (if a then b else c) else z)
标签: php html if-statement