Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q13 of 15
PHP - Variables and Data Types
What will be the output of the following PHP code?
$a = '5';
$b = 3;
$c = $a + $b;
echo gettype($c) . ' ' . $c;
Ainteger 8
Binteger 53
Cstring 8
Dstring 53
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the addition operation with mixed types

    PHP converts the string '5' to integer 5 automatically when used with + operator.
  2. Step 2: Determine the result type and value

    Adding 5 + 3 gives integer 8. gettype($c) returns 'integer' and echo prints 'integer 8'.
  3. Final Answer:

    integer 8 -> Option A
  4. Quick Check:

    String + int converts string to int = D [OK]
Quick Trick: PHP converts numeric strings to numbers in math operations [OK]
Common Mistakes:
  • Expecting string concatenation with + operator
  • Thinking result type stays string
  • Confusing + with . operator for strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes