PROGRAMMING

 
REMEMBERS




Last update:   04-01-2022

AND

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

OR

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

XOR

Evaluates to true if either the left and right operands evaluates to true, but not both.
 
$a = "1";
$b = "abc";

if (is_numeric($a) XOR is_numeric($b)) {
    echo "Only one number exists";
}
// Outputs: Only one number exists
... 1 lines
 

Note

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.

Contional operators

Ternary operator
 
$x = expr1  ? expr2 : expr3; // x = expr2 if expr1 = TRUE
Null coalescing
 
$x = expr1 ?? expr2 ; // x = expr1 if expr1 exists and not null

Questions    
Function definition

        A B C D E F
🔔
1/1