A three-mesh operator problem

Source: Internet
Author: User

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变成字符串后的结果等。

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.