Recall & Review
beginner
What is type coercion in PHP?
Type coercion is when PHP automatically converts one data type to another during operations, like turning a string into a number when needed.
Click to reveal answer
beginner
What happens when you add a string containing a number to an integer in PHP?<br>
$result = '5' + 3;
PHP converts the string '5' to the number 5, then adds 3, so
$result becomes 8.Click to reveal answer
intermediate
How does PHP treat a string that starts with numbers but has letters after when used in arithmetic?<br>
$result = '10abc' + 5;
PHP reads the starting number 10 and ignores the letters, so it adds 10 + 5 = 15.
Click to reveal answer
beginner
What is the result of adding a boolean to an integer in PHP?<br>
$result = true + 2;
PHP converts
true to 1, so the result is 1 + 2 = 3.Click to reveal answer
intermediate
What happens when you add a non-numeric string to a number in PHP?<br>
$result = 'hello' + 5;
PHP converts the non-numeric string to 0, so the result is 0 + 5 = 5.
Click to reveal answer
What does PHP do when adding '7' + 3?
✗ Incorrect
PHP automatically converts the string '7' to the number 7 and then adds 3, resulting in 10.
What is the result of '12abc' + 8 in PHP?
✗ Incorrect
PHP reads the numeric part '12' and adds 8, resulting in 20.
How does PHP treat true when used in arithmetic?
✗ Incorrect
PHP converts true to 1 in arithmetic operations.
What happens when you add 'hello' + 5 in PHP?
✗ Incorrect
Non-numeric strings convert to 0, so 0 + 5 = 5.
Which of these is NOT a type PHP coerces automatically?
✗ Incorrect
PHP does not automatically convert arrays to numbers in arithmetic operations.
Explain how PHP handles type coercion when adding a string and a number.
Think about how PHP reads the string before adding.
You got /4 concepts.
Describe what happens when a boolean is used in an arithmetic operation in PHP.
Booleans act like small numbers in math.
You got /3 concepts.