0
0
PHPprogramming~20 mins

Type coercion in operations in PHP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PHP Type Coercion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this PHP code with mixed types?
Consider the following PHP code snippet. What will it output?
PHP
<?php
$a = '5';
$b = 3;
$c = $a + $b;
echo $c;
?>
A8
B53
CError: Unsupported operand types
D5
Attempts:
2 left
💡 Hint
PHP converts strings to numbers when using arithmetic operators.
Predict Output
intermediate
2:00remaining
What does this PHP code output when comparing string and integer?
What is the output of this PHP code snippet?
PHP
<?php
var_dump('10' == 10);
var_dump('10' === 10);
?>
Abool(true) bool(true)
Bbool(false) bool(true)
Cbool(false) bool(false)
Dbool(true) bool(false)
Attempts:
2 left
💡 Hint
== compares values after type juggling, === compares both value and type.
Predict Output
advanced
2:00remaining
What is the output of this PHP code with boolean and string addition?
Analyze the following PHP code and select the correct output.
PHP
<?php
$x = true + '2 apples';
echo $x;
?>
A3
B1
C2 apples1
DError: Unsupported operand types
Attempts:
2 left
💡 Hint
PHP converts booleans to integers and strings to numbers when used with + operator.
Predict Output
advanced
2:00remaining
What error or output does this PHP code produce?
What happens when you run this PHP code?
PHP
<?php
$result = 'hello' - 5;
echo $result;
?>
A0
BError: Unsupported operand types
C-5
D5
Attempts:
2 left
💡 Hint
PHP converts non-numeric strings to 0 when used in arithmetic.
Predict Output
expert
2:00remaining
What is the output of this PHP code with array and string addition?
Consider this PHP code. What will it output or error?
PHP
<?php
$a = [1, 2];
$b = '3';
$c = $a + $b;
echo gettype($c);
?>
Astring
BError: Unsupported operand types
Cinteger
Darray
Attempts:
2 left
💡 Hint
PHP does not support adding arrays and strings with + operator.