Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q13 of 15
PHP - Functions
What will be the output of this PHP code?
function add($a, $b) {
  return $a + $b;
  echo "Done";
}
$result = add(3, 4);
echo $result;
A7
BDone7
C7Done
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand return stops function execution

    The return $a + $b; sends back 7 and stops the function, so echo "Done"; is never run.
  2. Step 2: Output the returned value

    The variable $result gets 7, and echo $result; prints 7 only.
  3. Final Answer:

    7 -> Option A
  4. Quick Check:

    Return stops function, only 7 printed [OK]
Quick Trick: Code after return inside function does not run [OK]
Common Mistakes:
  • Expecting code after return to execute
  • Confusing echo inside function with return
  • Thinking return prints output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes