Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q13 of 15
PHP - Functions
What will be the output of the following PHP code?
function add($a, $b) {
  return $a + $b;
}
echo add(3, 4);
A7
B34
CError: Missing return statement
D7.0
Step-by-Step Solution
Solution:
  1. Step 1: Understand function call with arguments

    The function add receives 3 and 4 as arguments for $a and $b respectively.
  2. Step 2: Calculate the return value

    The function returns the sum 3 + 4 = 7, which is then printed by echo.
  3. Final Answer:

    7 -> Option A
  4. Quick Check:

    3 + 4 = 7 [OK]
Quick Trick: Add numeric arguments to get sum output [OK]
Common Mistakes:
  • Concatenating numbers as strings
  • Expecting float output without decimals
  • Thinking function lacks return

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes