PROGRAMMING

 
REMEMBERS




Last update:   29-10-2021

Operators

Equivalence == / !=

Evaluates to true if the two operands are equivalent.

Identity === / !==

Evaluates to true only if the operands are of the same data type and the same value.
 
$domain = 'xn--google.com';
$finded = (stripos($domain, 'xn--') === 0) ? "true" : "false"; 

echo $finded; // true - Correct

$domain2 = 'google.com';
$finded = (stripos($domain2, 'xn--') == 0) ? "true" : "false";

echo $finded; // true - Incorrect
... 1 lines
 
It's easy to confuse the assignment operator = for the comparison operator ==
 
echo $a == 10;

echo 10 == $a; // better
if you had forgotten one of the equal signs, the parser would have thrown an error.
 
$a = 9;

if ($a == 10) {}

if ($a = 10) {} // No alert error

if (10 = $a) {} //  Parse error: syntax error, unexpected '='

Inequality < / <=

While the process is clear for numbers, things change a bit for other data types.
 
$left = "ABC";
$right = "ABD";

echo (int) ($left > $right); // output 0

    // because the letter D in $right is higher 
    // than the corresponding letter C in $left

$left = 'apple';
$right = 'Apple';

echo (int) ($left > $right); // output 1

    // because the ASCII value of the character a (97) is
    // than that of the character A (65)
... 5 lines
 

Questions    
Logical Operators

        A B C D E F
🔔
1/5