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 = 2;
$c = $a / $b;
echo (int)$c;
A2.5
B3
CError
D2
Step-by-Step Solution
Solution:
  1. Step 1: Calculate division result

    $a / $b = 5 / 2 = 2.5 (float)
  2. Step 2: Cast float to integer

    (int)2.5 converts to 2 by dropping decimal part.
  3. Final Answer:

    2 -> Option D
  4. Quick Check:

    Integer cast truncates decimals = 2 [OK]
Quick Trick: Casting float to int drops decimals [OK]
Common Mistakes:
  • Expecting rounding instead of truncation
  • Confusing output with float value
  • Thinking casting causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes