Challenge - 5 Problems
Master of PHP Comparison Operators
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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);
Attempts:
2 left
💡 Hint
Loose equality compares values after type juggling.
✗ Incorrect
The loose equality operator (==) converts types if needed. Here, integer 0 and string '0' are considered equal, so var_dump outputs bool(true).
❓ Predict Output
intermediate2: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);
Attempts:
2 left
💡 Hint
Strict equality checks both value and type.
✗ Incorrect
The strict equality operator (===) requires both value and type to be the same. Here, integer 0 and string '0' differ in type, so var_dump outputs bool(false).
❓ Predict Output
advanced2: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);
Attempts:
2 left
💡 Hint
Loose equality considers null equal to empty string.
✗ Incorrect
In PHP, null and empty string are NOT equal with loose equality (==). So var_dump outputs bool(false).
❓ Predict Output
advanced2: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);
Attempts:
2 left
💡 Hint
Loose equality converts both to boolean for comparison.
✗ Incorrect
When comparing false and '0' with loose equality, PHP converts '0' to false, so they are equal and var_dump outputs bool(true).
❓ Predict Output
expert2: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);
Attempts:
2 left
💡 Hint
Empty arrays and empty strings are equal with loose equality.
✗ Incorrect
In PHP, an empty array and an empty string are NOT equal with loose equality (==). So var_dump outputs bool(false).