Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q5 of 15
PHP - Operators
What will be the output of this PHP code?
$x = 15;
$x /= 3;
$x -= 2;
echo $x;
A5
B1
C8
D3
Step-by-Step Solution
Solution:
  1. Step 1: Perform division assignment

    $x starts at 15. After $x /= 3;, $x becomes 5.
  2. Step 2: Perform subtraction assignment

    Then $x -= 2; subtracts 2, so $x becomes 3.
  3. Final Answer:

    3 -> Option D
  4. Quick Check:

    Division then subtraction updates $x = 3 [OK]
Quick Trick: Divide then subtract using /= and -= [OK]
Common Mistakes:
  • Subtracting before dividing
  • Confusing /= with *= operator
  • Not updating variable after operations

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes