PHP basic Trap question (variable assignment) _php tutorial

Source: Internet
Author: User
Copy CodeThe code is as follows:
$a = 3;
$b = 6;
if ($a =5| | $b =7) {
$a + +;
$b + +;
}
Var_dump ($a, $b);


Trap One

Take $a=5, $b = 7 as $a==5, $b ==7
Error Result: 3,6

Trap Two

Operator precedence, $a=5 assignment is considered successful $b=7 not executed
Error Result: 6,7

Correct understanding

The trap is the precedence of the operator, and the assignment operator (=) has the lowest precedence, so the correct understanding should be
$a = (5| | $b =7)
Correct result: true,7

Upgrade
Deformation one
Copy CodeThe code is as follows:
$a = 3;
$b = 6;
$c = 1;
if ($a =5| | $b =7 && $c =10) {
$a + +;
$b + +;
}
Var_dump ($a, $b, $c);

deformation two
Copy CodeThe code is as follows:
$a = 3;
$b = 6;
$c = 1;
if ($a =0| | $b =7 && $c =10) {
$a + +;
$b + +;
}
Var_dump ($a, $b, $c);

Interested students can think about:)

http://www.bkjia.com/PHPjc/326013.html www.bkjia.com true http://www.bkjia.com/PHPjc/326013.html techarticle Copy the code as follows: PHP $a =3; $b =6; if ($a =5| | $b =7) {$a + +; $b + +;} var_dump ($a, $b); Trap a $a=5, $b = 7 as the $a==5, $b ==7 error results: 3,6 trap Two operators of the excellent ...

  • 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.