Bird
0
0

Given the code below, what will be the value of $result after execution?

hard📝 Application Q15 of 15
PHP - Operators
Given the code below, what will be the value of $result after execution?
$x = 4;
$y = 3;
$result = 10;
$result += $x * $y;
$result -= 5;
$result /= 2;
A8.5
B6.5
C10
D9
Step-by-Step Solution
Solution:
  1. Step 1: Calculate multiplication and addition

    $x * $y = 4 * 3 = 12. Then $result += 12 means 10 + 12 = 22.
  2. Step 2: Subtract 5 from $result

    22 - 5 = 17.
  3. Step 3: Divide $result by 2

    17 / 2 = 8.5.
  4. Step 4: Check options carefully

    8.5 is 8.5, but note the question asks for final value of $result after all operations.
  5. Final Answer:

    8.5 -> Option A
  6. Quick Check:

    (10 + 4*3 - 5) / 2 = 8.5 [OK]
Quick Trick: Follow order: multiply, add, subtract, divide [OK]
Common Mistakes:
  • Ignoring operator precedence
  • Doing operations in wrong order
  • Dividing before subtracting

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes