Memory App
Php
 




Equivalence Operator

== / != Evaluates to true if the two operands are equivalent. (1/3)

Identity Operator

=== / !== Evaluates to true only if the operands are of the same data type and the same value.

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

$domain = 'google.com';
echo $finded = (stripos($domain, 'xn--') == 0) ? "true" : "false";
    // Output: true
    // Wrong (FALSE == 0 returns TRUE)
    // Identical operator must be used insteed
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 '='
(2/3)

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)

Questions










Top Reference > Programming
0/0 (80)  
Save
5