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
We look at a code!
strange, and / && and or / || out of the results are different. Question Where is it?
More strange, how is it right? So the problem may appear in =, some Google and documents, finally found the answer!
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.
|Cloning and NEW||Cloning and New|
|Type and self-increment / self-reduction||No combination|
|+ -.||Arnstruation and string|
|> =||comparative operation|
|==! = ===! ==||< Comparative operation|
|Binding operation||Left||| Bit operation|
|| | logic operation||left|
|= + = – = * = / =. =% = & =||= ^ => = => | assignment|