我想每个人都给出了解决方案,我想贡献出意外结果的原因。
首先,您可以在这里检查原点,以及如何评估运算符(左、右、关联等)。
http://php.net/manual/fa/language.operators.precedence.php
现在,如果我们分析你的句子。
$ paperType = 'bond';
$ description = 'Paper:'. ($ paperType == 'bond')? 'Bond': 'Other';
1)我们查看表格,发现括号首先被评估,然后是“。” (连接)被评估,最后是三元运算符'?',因此我们可以将其关联如下:
// evaluate the parenthesis ... ($ paperType == 'bond')
$ description = ('Paper:'. 1)? 'Bond': 'Other';
//result
$ description = 'Paper: 1'? 'Bond': 'Other';
2)我们现在有了三元运算符,我们知道一个字符串被评估为“真”
// php文档 转换为布尔值时,以下值被认为是FALSE:
...空字符串和字符串“0”
$ description = true? 'Bond': 'Other';
3) 最后
$ description = 'bond';
我希望我已经澄清了这个问题。问候。