Challenge - 5 Problems
PHP Type Juggling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of loose comparison with string and integer
What is the output of this PHP code?
$a = "10 apples";
$b = 10;
var_dump($a == $b);
PHP
$a = "10 apples"; $b = 10; var_dump($a == $b);
Attempts:
2 left
💡 Hint
PHP converts the string to a number when using ==.
✗ Incorrect
When comparing a string to a number with ==, PHP converts the string to a number until it hits a non-numeric character. "10 apples" becomes 10, so 10 == 10 is true.
❓ Predict Output
intermediate2:00remaining
Result of adding string and integer
What is the output of this PHP code?
$x = "5 cats" + 3;
var_dump($x);
PHP
$x = "5 cats" + 3; var_dump($x);
Attempts:
2 left
💡 Hint
PHP converts strings to numbers when using arithmetic operators.
✗ Incorrect
The string "5 cats" is converted to the number 5, then 3 is added, resulting in 8 as an integer.
❓ Predict Output
advanced2:00remaining
Output of loose comparison with boolean and string
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
When comparing boolean and string, PHP converts string to boolean.
✗ Incorrect
The string "0" is considered false in boolean context, so false == false is true.
❓ Predict Output
advanced2:00remaining
Output of strict comparison with integer and string
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 comparison checks both value and type.
✗ Incorrect
The integer 0 and string "0" have different types, so === returns false.
❓ Predict Output
expert3:00remaining
Output of arithmetic with null and string
What is the output of this PHP code?
$a = null;
$b = "10";
$c = $a + $b;
var_dump($c);
PHP
$a = null; $b = "10"; $c = $a + $b; var_dump($c);
Attempts:
2 left
💡 Hint
Null is treated as zero in arithmetic operations.
✗ Incorrect
Null is converted to 0, string "10" is converted to 10, sum is 10 as integer.