Bird
0
0

What is wrong with this PHP code?

medium📝 Debug Q7 of 15
PHP - Functions
What is wrong with this PHP code?
function add($a, $b) {
    return $a + $b;
}
echo add(5);
AFunction declared incorrectly
BReturn statement missing semicolon
CFunction call missing one argument
DEcho cannot print function return
Step-by-Step Solution
Solution:
  1. Step 1: Check function parameters

    The function add expects two arguments: $a and $b.
  2. Step 2: Check function call

    Calling add(5) provides only one argument, causing an error.
  3. Final Answer:

    Function call missing one argument -> Option C
  4. Quick Check:

    Function call must match parameters [OK]
Quick Trick: Match number of arguments to parameters [OK]
Common Mistakes:
  • Calling function with fewer arguments
  • Missing semicolon in return
  • Thinking echo can't print return

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes