PHP operator problems-php Tutorial

Source: Internet
Author: User
Why if ($ a100 & amp; $ b200) {var_dump ($ a, $ B) ;}output bool (true) int (200) {code ...}

Why?if ($a = 100 && $b = 200) {var_dump($a, $b);}Output bool (true) int (200)


  

Reply content:

Why?if ($a = 100 && $b = 200) {var_dump($a, $b);}Output bool (true) int (200)


   

&&Priority ratio=High, so will$a = (100 && $b = 200)In http://php.net/manual/en/language.operators.precedence.php
Although = has a lower precedence than most other operators, PHP will still allow expressions similar to the following: if (!$a = foo()), in which case the return value of foo() is put into $a., Although&&Priority higher=,200Will be assigned$b, Because100 && $b = 200Returns truetrue, So$a=true

The actual priority is as follows:


    

Therefore, $ a is true.

Assignment is not a comparison. you may have read it wrong.

I have been talking about it all the time.

Actually, this is how it runs.

php
if($a = (100 && $b = 200)){ var_dump($a, $b);}

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.