In PHP, and is used for logical judgment. The syntax is "value 1 and value 2". If the operands on both sides of and are true, then return true, otherwise return false; and is a logical operator , like the "&&" operator, both represent logical "AND", and the "&&" operator has a higher priority than and.
The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer
The 'and' operator in PHP is called a logical operator. If both operands are true, return true.
Example:
Copy after login
Output: False
Explanation: Since variable $a = 100 and another variable $b = 10, the condition $a == 100 is calculated The result is true, and $b == 10 evaluates to true. Therefore, '$a == 100 and $b == 10' evaluates to true because AND logic says that if both operands are true, the result is also true. But when $b = 20 is input, the condition $b == 10 is false, so the AND operation result will be false.
The ‘&&’ operator in PHP is also called a logical operator. If both operands are true, return true.
Example:
Copy after login
Output: True
Explanation: Since variable $a = 100 and another variable $b = 10, the calculation result of condition $a == 100 is true, and pow($b,2)==$a also evaluates to true because $b = 10 raised to the power of 2 is 100, which is equal to $a. Therefore, '$a == 100 && pow($b,2)==$a' evaluates to true because AND logic states that the AND operation will be true only if both operands are true. But when $b = 20 is input, the condition pow($b,2)==$a is false, so the AND operation result is false.
Comparison between 'AND' and '&&' operators:
Based on precedence:
Priority basically determines which operations are performed first in an expression. The '&&' operator has high precedence, and the 'AND' operator has low precedence.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What is the usage of and in PHP. For more information, please follow other related articles on the PHP Chinese website!