0

假设我们有代码

$somestring = "amazing text" . $something . "lol";

是否有可能仅在某些情况下以某种方式添加 $something 部分

$myvar == true

但没有做:

if ($myvar) 
   $somestring = "amazing text" . $something . "lol";
else
   $somestring = "amazing text" . "lol";

像内联的东西

$somestring = "amazing text" . if($myvar) $something . "lol";

这会很不错。

4

2 回答 2

3
$somestring = "amazing text".($myvar ? $something : "")."lol";

文档

于 2013-01-25T20:49:58.740 回答
1
$somestring = "amazing text" . ($myvar?$something:'') . "lol";
于 2013-01-25T20:50:36.797 回答