And and && Picking Guide in PHP

I originally thought that the and && is the same in PHP, just written in order to readability and beautiful, in fact I am wrong. This is a pit!
Look at the following code:

$ ba = true; $ bb = false; $ b1 = $ ba and $ bb; $ b2 = $ ba && $ bb; var_dump ($ b1); // $ b1 = Truevar_dump ($ b2); // $ b2 = false $ ba = false; $ bb = true; $ b3 = $ ba = bb; $ b4 = $ ba || $ bb; var_dump ($ b3); //// $ b3 = falsevar_dump ($ b4); // $ b4 = true
   strange, and / && and or / || out of the results are different. Question Where is it? 
We look at a code!


$ ba = true; $ bb = false; var_dump ($ ba and bb); // Falsevar_dump ($ BA && $ B); // False $ ba = false; $ bb = true; var_dump ($ ba or $ bb); // Truevar_dump ($ ba || $ bb); // true
  More strange, how is it right? So the problem may appear in =, some Google and documents, finally found the answer!  
Operation Priority

Through this table, we can see the and / && and or / || The priority of the two sets of operators is different. And and OR is low.The code above, so the code is good, it is to assign a value first, and then a logical operation of an AND or or OR. The result of this operation is not stored. So finally coming out to make our incredible results.

Combination

Operator

Additional information Cloning and NEW Cloning and New array ** ++ – ~ ( INT) (String) (BOOL) (BOOL) @ Right ! Logic operation Left * /% Arithmetic + -. Arnstruation and string left > No combination No combination ^ | | logic operation left ?: Trimed Conditions Right > = => | assignment left XOR Left left ,
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment

right
Type and self-increment / self-reduction No combination
> = comparative operation
==! = ===! == < Comparative operation
& < left
Binding operation Left | Bit operation
left && Logic operation
= + = – = * = / =. =% = & = = ^ =
OR logic operation <