三元运算问题

WBOY
Release: 2016-06-23 13:30:50
Original
852 people have browsed it

$str = true?8888:true?100+100:100000000;echo '<br/>',$str;
Copy after login


为什么我这里结果输出的是200呢? 结合方向是左, 从第一三元运算符开始 为真 已经确定了 是8888 ,“:”后面的 不执行了的。难道不是这样?


回复讨论(解决方案)

$str = true?8888:(true?100+100:100000000); echo '<br/>',$str;
Copy after login


这样就对了

$c=1;$d=1;$str = true?8888:(true?$c++:$d++); echo $c,"<br/>";//1echo $d,"<br/>";//1echo '<br/>',$str;//8888
Copy after login

$str = (true?8888:true)?100+100:100000000; echo '<br/>',$str;//  200
Copy after login


如果不加括号系统是这样解释的。

23$str = (true?8888:true)?100+100:100000000;  echo '<br/>',$str;//  200
Copy after login


系统会这样解析?  三元运算符的 结合方向不是左吗?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template