如果是一个自我陈述。这就像一个完整的声明。因此,不能在字符串左右连接之间使用它。更好的解决方案是使用速记三元运算符
(conditional expression)?(ouput if true):(output if false);
也可以在字符串连接中使用。范例:
$i = 1 ; $result = 'The given number is'.($i > 1 ? 'greater than one': 'less than one').'. So this is how we cuse ternary inside concatenation of strings';
您还可以使用嵌套三元运算符:
$i = 0 ; $j = 1 ; $k = 2 ; $result = 'Greater One is'. $i > $j ? ( $i > $k ? 'i' : 'k' ) : ( $j > $k ? 'j' :'k' ).'.';


![if语句在串联中?[关闭] if语句在串联中?[关闭]](http://www.mshxw.com/aiimages/31/443180.png)
