Skip to main content
PHP Output Prediction Hard +35 XP

Strict Comparison

What is the result of this comparison?

PHPRead-only
var_dump(0 == "foo");  // PHP 7
var_dump(0 === "foo");

What is the output?

Show answer and explanation

Answer: true then false

In PHP 7, 0 == 'foo' is true (loose comparison coerces 'foo' to 0). === (strict) checks type too, so false.

Hint: PHP's loose comparison has surprising behavior.

What this challenge tests

Output Prediction in PHP: comparison, type-juggling.

Related challenges