Bird
0
0

What is the output of this PHP code?

medium📝 Predict Output Q4 of 15
PHP - Type Handling
What is the output of this PHP code?
$a = '3 apples';
$b = 2;
echo $a * $b;
AError
B0
C3 apples3 apples
D6
Step-by-Step Solution
Solution:
  1. Step 1: Understand string to number conversion in multiplication

    PHP converts '3 apples' to integer 3 when used in arithmetic.
  2. Step 2: Multiply 3 by 2

    3 * 2 equals 6.
  3. Final Answer:

    6 -> Option D
  4. Quick Check:

    String with leading number converts to that number [OK]
Quick Trick: Strings starting with digits convert to those digits in math [OK]
Common Mistakes:
  • Expecting string output
  • Assuming error on mixed types
  • Confusing multiplication with concatenation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes