Don't know the result why is "excessive"? Ask the friend to know the answer under
Reply content:
Don't know the result why is "excessive"? Ask the friend to know the answer under
By modifying the values, combining the results to analyze it.
Can see that $ A is true when executed ($a = = 5)? 1:0 for false $b = = 10
This result is true when returning excessive, for false return: (
For the convenience of reading best in ($a = = 5)? 1:0 Plus parentheses
I can only say JS ran out isyay
Does PHP do this?
($a ? ($a == 5 ? "yay" : "nay") : $b == 10) ? "excessive" : ":(";
If you're writing your own code, it might be easier to add parentheses, as the following should be a JavaScript-like result.
echo $a ? ($a == 5 ? "yay" : "nay") : ($b == 10 ? "excessive" : ":(");
If I'm right, I'm going to look straight in the back and divide the statement.
By partitioning can be simplified into
echo ' Yay '? ' Excessive ': ':(';
这样结果就会变掉
$a == 5 是真 返回yay
($a) ? ($a == 5) ? 'yay' : 'nay' : ($b == 10) ? 'excessive' : ':('; 这种写法你是从左往右读的,但机器不这么读,它可能是这样读的 ($a) ? (($a == 5) ? 'yay' : 'nay' : ($b == 10) ? 'excessive') : ':('; 电脑头都晕了
$a ? ($a == 5 ? 'yay' : 'nay') : ($b == 10 ? 'excessive' : ':('); 以后这样写,好吗
在语言设计上,js重输出,而php重计算。
类似的差别还有&&符和||符的计算结果、null变成字符串后的结果等。