PHP Output Prediction Medium +20 XP
Type Coercion
What does this output?
PHPRead-only
$a = "5 apples"; $b = 3; echo $a + $b;
What is the output?
Show answer and explanation
Answer: 8
PHP coerces '5 apples' to integer 5 when used in arithmetic. 5 + 3 = 8. PHP silently extracts the leading number.
Hint: PHP extracts the leading number from the string.
What this challenge tests
Output Prediction in PHP: type-coercion, arithmetic.