0
0
PHPprogramming~20 mins

Comparison operators (loose and strict) in PHP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of PHP Comparison Operators
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of loose equality with different types
What is the output of this PHP code?
$a = 0;
$b = '0';
var_dump($a == $b);
PHP
$a = 0;
$b = '0';
var_dump($a == $b);
Astring(1) "0"
Bbool(false)
Cint(0)
Dbool(true)
Attempts:
2 left
💡 Hint
Loose equality compares values after type juggling.
Predict Output
intermediate
2:00remaining
Output of strict equality with different types
What is the output of this PHP code?
$a = 0;
$b = '0';
var_dump($a === $b);
PHP
$a = 0;
$b = '0';
var_dump($a === $b);
Abool(true)
Bbool(false)
Cint(0)
Dstring(1) "0"
Attempts:
2 left
💡 Hint
Strict equality checks both value and type.
Predict Output
advanced
2:00remaining
Result of comparing null and empty string with loose equality
What is the output of this PHP code?
$a = null;
$b = '';
var_dump($a == $b);
PHP
$a = null;
$b = '';
var_dump($a == $b);
Abool(false)
BNULL
Cbool(true)
Dstring(0) ""
Attempts:
2 left
💡 Hint
Loose equality considers null equal to empty string.
Predict Output
advanced
2:00remaining
Output of comparing boolean false and string '0' with loose equality
What is the output of this PHP code?
$a = false;
$b = '0';
var_dump($a == $b);
PHP
$a = false;
$b = '0';
var_dump($a == $b);
Abool(false)
Bint(0)
Cbool(true)
Dstring(1) "0"
Attempts:
2 left
💡 Hint
Loose equality converts both to boolean for comparison.
Predict Output
expert
2:00remaining
Output of comparing array and string with loose equality
What is the output of this PHP code?
$a = [];
$b = '';
var_dump($a == $b);
PHP
$a = [];
$b = '';
var_dump($a == $b);
Abool(false)
Bbool(true)
Carray(0) {}
Dstring(0) ""
Attempts:
2 left
💡 Hint
Empty arrays and empty strings are equal with loose equality.