Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q4 of 15
PHP - Functions
What will be the output of this PHP code?
function sayHi() {
  echo "Hi! ";
}
sayHi();
sayHi();
AHi! Hi!
BHi!
CsayHi() sayHi()
DError: function not defined
Step-by-Step Solution
Solution:
  1. Step 1: Understand function behavior

    The function sayHi() prints "Hi! " each time it is called.
  2. Step 2: Count the function calls

    The function is called twice, so it prints "Hi! " two times.
  3. Final Answer:

    Hi! Hi! -> Option A
  4. Quick Check:

    Function called twice prints twice = A [OK]
Quick Trick: Each function call runs its code once [OK]
Common Mistakes:
  • Thinking function runs only once
  • Expecting function name to print

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes