Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q5 of 15
PHP - String Functions
What will be the output of this PHP code?
$result = strncasecmp('HelloWorld', 'helloThere', 5);
echo $result;
A-1
B0
C1
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand strncasecmp() usage

    It compares first 5 characters ignoring case.
  2. Step 2: Compare first 5 chars

    'Hello' vs 'hello' are equal ignoring case, so result is 0.
  3. Final Answer:

    0 -> Option B
  4. Quick Check:

    First 5 chars equal ignoring case = 0 [OK]
Quick Trick: strncasecmp() returns 0 if first n chars match ignoring case [OK]
Common Mistakes:
  • Expecting case-sensitive result
  • Confusing with strcmp()
  • Assuming it compares full strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes