Memory Refresh
Php



Logical





AND operator (&& / and)

Evaluates to true if both the left and right operands evaluate to true <?php if (isset($a) AND isset($b)) { // a and b is set }

OR operator (|| / or)

Evaluates to true if either the left or right operands evaluate to true. <?php if (isset($a) OR isset($b)) { // a, b, a and b - could be set }

XOR operator (xor)

Evaluates to true if either the left and right operands evaluates to true, but not both <?php $a = "1"; $b = "abc"; if (is_numeric($a) XOR is_numeric($b)) { echo "Only one number exists"; } // Outputs: Only one number exists It's important to understand that all logical operators only work with Boolean values. PHP will first convert any other value to a Boolean and then perform the operation.