Copy code The code is as follows:
$a=3;
$b= 6;
if($a=5||$b=7){
$a++;
$b++;
}
var_dump($a, $b);
Trap 1
Considering $a=5, $b=7 as $a==5, $b==7
Error result: 3,6
Trap 2
Operator priority, it is considered that $a=5 is assigned successfully and $b=7 is not executed
Error result: 6,7
Correct understanding
The trap is the priority of operators. The assignment operator (=) has the lowest priority, so the correct understanding should be
$a=(5||$b=7)
Correct Result: true,7
Upgrade
Transformation 1
Copy code The code is as follows:
$a=3;
$b=6;
$c=1;
if($a=5||$b=7 && $c=10){
$a++;
$b++;
}
var_dump($a, $b,$c);
Variation 2
Copy code The 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 it:)
http://www.bkjia.com/PHPjc/326013.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326013.htmlTechArticleCopy the code as follows: ?php $a=3; $b=6; if($a=5| |$b=7){ $a++; $b++; } var_dump($a, $b); Trap: $a=5, $b=7 is regarded as $a==5, $b==7, error Result: 3,6 Advantages of the trap binary operator...