if语句在串联中?[关闭]

if语句在串联中?[关闭],第1张

if语句在串联中?[关闭]

如果是一个自我陈述。这就像一个完整的声明。因此,不能在字符串左右连接之间使用它。更好的解决方案是使用速记三元运算符

    (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' ).'.';


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5152831.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-18
下一篇 2022-11-18

发表评论

登录后才能评论

评论列表(0条)

保存