Bird
0
0

What is the output of this PHP code?

medium📝 Predict Output Q4 of 15
PHP - Functions
What is the output of this PHP code?
function add($x, $y = 5) {
  return $x + $y;
}
echo add(10);
A15
B10
C5
DError: Missing argument
Step-by-Step Solution
Solution:
  1. Step 1: Identify default parameter usage

    Function add has $y defaulting to 5 if not provided.
  2. Step 2: Call add with one argument

    Calling add(10) means $x=10, $y uses default 5, so sum is 15.
  3. Final Answer:

    15 -> Option A
  4. Quick Check:

    Default parameter used = 15 output [OK]
Quick Trick: Missing argument uses default value in calculation [OK]
Common Mistakes:
  • Expecting error for missing argument
  • Ignoring default parameter value
  • Adding only one parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes