Bird
0
0

What is the output of the following PHP code?

medium📝 Predict Output Q13 of 15
PHP - String Functions
What is the output of the following PHP code?
$name = "john doe";
echo ucfirst($name);
AJohn doe
Bjohn Doe
CJOHN DOE
Djohn doe
Step-by-Step Solution
Solution:
  1. Step 1: Understand ucfirst() behavior

    ucfirst() capitalizes only the first character of the entire string, leaving the rest unchanged.
  2. Step 2: Apply to given string

    Input is "john doe". After ucfirst(), it becomes "John doe" (only first letter capitalized).
  3. Final Answer:

    John doe -> Option A
  4. Quick Check:

    ucfirst("john doe") = "John doe" [OK]
Quick Trick: ucfirst() capitalizes only first letter of whole string [OK]
Common Mistakes:
  • Expecting all words capitalized
  • Confusing ucfirst() with ucwords()
  • Assuming it converts whole string to uppercase

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes