ExpertRefresh

Operators / Comparison  

Related Pages

Aritmetic
String
Comparison
Logical
Bitwise


0.0% 100%
 
 
0 pages 298 questions
1) What is the result when using stripos? <?php echo $finded = (stripos('xn--google.com', 'xn--') === 0) ? "true " : "false"; echo $finded = (stripos('google.com', 'xn--') == 0) ? "true " : "false";





2) Which of the following statements will produse a Parse error?





3) Which returns true?







Equivalence Operator (== / !=)
Evaluates to true if the two operands are equivalent.
Identity Operator (=== / !==)
Evaluates to true only if the operands are of the same data type and have the same value.
Example <?php $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 == <?php echo $a == 10; echo 10 == $a; // better These two operations are completely identical, but, because the left-hand operator of an assignment must be a variable, if you had forgotten one of the equal signs, the parser would have thrown an error, thus alerting you to your mistake. <?php $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. <?php $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)


References