我们说我们有代码
$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";
非常好。
答案 0 :(得分:3)
$somestring = "amazing text".($myvar ? $something : "")."lol";
答案 1 :(得分:1)
$somestring = "amazing text" . ($myvar?$something:'') . "lol";