Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q4 of 15
PHP - String Functions
What will be the output of the following PHP code?
$result = strcmp('Apple', 'apple');
echo $result;
A-1
B0
C1
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand strcmp() behavior

    strcmp() compares strings case-sensitively; 'A' (ASCII 65) is less than 'a' (ASCII 97).
  2. Step 2: Determine comparison result

    Since 'Apple' is less than 'apple', strcmp() returns a negative number, commonly -1.
  3. Final Answer:

    1 -> Option C
  4. Quick Check:

    Case-sensitive compare 'Apple' < 'apple' = positive or negative? Actually, 'A' (65) < 'a' (97), so strcmp('Apple','apple') returns negative number, typically -32 or -1 depending on implementation.
Quick Trick: strcmp() returns negative if first string is less [OK]
Common Mistakes:
  • Assuming case-insensitive comparison
  • Expecting 0 for different cases
  • Thinking output is a boolean

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes