What are the differences between php logical operators
Xiaobian to share with you what are the differences between php logical operators, I believe most people do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!
Difference: 1, and and "&&" operators are used to indicate logical AND, and has lower priority,"&&" has higher priority;2, or and "||"Operators are used to indicate logical OR, or has lower precedence,"||The "$" operator is used to indicate logical NOT;4. The xor operator is used to indicate logical XOR.
Operating environment: Windows 10 system, PHP 7.1 version, Dell G3 computer.
What is the difference between PHP logical operators?
php logical operator
I always thought that "or" and "in PHP||"They can be equated, but they are not. There is a difference in priority. Here is an example of how they differ:
After execution,$a is true and $b is false. This is because "||"priority is greater than"=", execute false first|| true, and then assign the result true to $a after execution. If "or" has priority less than "=", assign false to $b first, so $b is false.
The logical AND operation in PHP has two forms: AND and &&, and the OR operation has OR and|| Two forms.
If two separate expressions are involved in an operation, the result of both forms is exactly the same, for example,$a AND $b and $a && $b are not different. Same $a OR $b and $a|| $b is exactly the same.
However, the two forms of logical operators have different priorities. The priorities of these four symbols are allowed from high to low: &&,||、AND、OR。Pay special attention to this sentence, which should be carefully understood. Examples:
$a || $b AND $c || $d
Equivalent to:
($a || $b) AND ($c || $d)
The above is "php logical operators what are the differences between" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!