0
0
PHPprogramming~20 mins

Type juggling in PHP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PHP Type Juggling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
Aint(10)
Bbool(false)
Cbool(true)
Dstring(9) "10 apples"
Attempts:
2 left
💡 Hint
PHP converts the string to a number when using ==.
Predict Output
intermediate
2: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);
Aint(53)
Bint(8)
Cfloat(8.0)
Dstring(5) "5 cats"
Attempts:
2 left
💡 Hint
PHP converts strings to numbers when using arithmetic operators.
Predict Output
advanced
2: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);
Abool(true)
Bbool(false)
Cint(0)
Dstring(1) "0"
Attempts:
2 left
💡 Hint
When comparing boolean and string, PHP converts string to boolean.
Predict Output
advanced
2: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);
Abool(false)
Bbool(true)
Cint(0)
Dstring(1) "0"
Attempts:
2 left
💡 Hint
Strict comparison checks both value and type.
Predict Output
expert
3: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);
Astring(2) "10"
BTypeError
Cint(0)
Dint(10)
Attempts:
2 left
💡 Hint
Null is treated as zero in arithmetic operations.