And*_*tts 4 php string concatenation ternary-operator ternary
我想检查2个变量是否相同,如果是,则回显一个字符串.这可能在连接中吗?并且没有创建单独的功能吗?
例如
$var = 'here is the first part and '. ( $foo == $bar ) ? "the optional middle part" .' and the rest of the string.'
编辑
请注意,我想看看是否有办法做到这一点没有了: ''.如果你愿意的话,是"二元运算符".
Ant*_*ony 10
不要试图过多地缩短事情.你需要它: ''才能让事情发挥作用.
用于(condition) ? "show when true" : ""根据条件显示可选文本.三元运算符以这种方式命名,因为它由3部分组成.
$var = 'here is the first part and '. (( $foo == $bar ) ? "the optional middle part" : "") .' and the rest of the string.';
Run Code Online (Sandbox Code Playgroud)