+

& # 39; AND & # 39; vs & # 39; & amp; & amp; & # 39; as an operator in PHP

The AND operator is called a logical operator. It returns true if both operands are correct. 
Example :  
// Variable declaration and
// initialization $a = 100; $b = 50;  
// Check the two conditions using // And operator if ( $a == 100 and $b == 10) echo "True" ; else echo " False " ; ?>
Exit:
False
Explanation:Since the variable $a = 100 and the other variable $b = 10, the condition $a == 100 evaluates to true, and $b == 10 also evaluates to true. Therefore, $a == 100 and $b == 10 evaluate to true because the AND logic states that if both operands are true, then the result will also be true. But when the input is $b = 20, the condition $b == 10 is false, so the result of the AND operation will be false. The & amp; & amp; Operator & amp; & amp; is called a logical operator. Returns true if both operands are correct. 
Example :  
// Declare a variable and initialize it $a = 100; $b = 10;  
// Check status if ( $a = = 100 & amp; & amp; pow ( $b , 2) == $a ) echo "True" ; else echo " False " ; ?>
Exit:
True
Explanation:Since the variable $a = 100 and the other variable $b = 10, the condition $a == 100 evaluates to true, and pow ($b, 2) == $a also evaluates to true, since $b = 10 rises to a strength of 2 equal to 100, which is equal to $a. Hence ` $a == 100 & amp; & amp; pow ($b, 2) == $a ` evaluates to true because the AND logic indicates that only when both operands are true will the result of the AND operation be true. But when the input $b = 20, the condition pow ($b, 2) == $a is false, so the result of the AND operation is false.Comparison between the AND operators and & amp; & amp ; ".Here are some of the differences between the operators:
  • Based on Priority:The priority mainly decides which operations are performed first in the expression. Operator precedence ` & amp; & amp; amp ` high, and the priority of the operator ` AND ` low.
  • Based on transaction:
    Example :  
    // Expression for using the & amp; & amp; operator $bool = TRUE & amp; & amp; FALSE;  
    // Show the result of the operation & amp; & amp; echo ( $bool ? `TRUE` : ` FALSE` ), "" ;  
    // Expression for using the AND operator $bool = TRUE and FALSE;  
    // Show the result of the AND operation echo ( $bool ? `TRUE` : ` FALSE` ); ?>
    Exit:
    FALSE TRUE
    Explanation:
    The result of both operators is different if the operands are the same. The first expression evaluates to FALSE and the second expression is TRUE although both use the same operation.
    • The first expression, $bool = TRUE & amp; & amp; FALSE; evaluates to FALSE, because the & amp; & amp; operation is performed first, then the result is assigned to $bool because the precedence of the & amp; & amp; higher than priority =.
    • The second expression, $bool = TRUE and FALSE; evaluates to TRUE, because the and operator is lower takes precedence over the "=" operator, so the TRUE value that is to the right of the = is assigned to $bool, and then the "and" operation is performed internally, but not assigned, so $bool is now TRUE.
    For clarification, the fundamental difference between the AND operator and the & amp; & amp; lies in their difference in priority, but they both perform the same operation.
Get Solution for free from DataCamp guru