Ternary arithmetic problem

Source: Internet
Author: User
$str = True?8888:true?100+100:100000000;echo '
', $str;


Why am I outputting 200 of the results here? The binding direction is left, starting with the 13th unary operator for the real has been determined to be 8888, ":" After the not executed. Isn't that so?


Reply to discussion (solution)

$str = true?8888: (true?100+100:100000000); Echo '
', $str;


That's right.

$c =1; $d =1; $str = true?8888: (true? $c + +: $d + +); Echo $c, "
";//1echo $d,"
";//1echo '
', $str;//8888

$str = (true?8888:true)? 100+100:100000000; Echo '
', $str;// 200


This is explained by the system without parentheses.

23$str = (true?8888:true)? 100+100:100000000;  Echo '
', $str;// 200


Will the system parse this way? is the binding direction of the ternary operator not left?
  • Related Article

    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.