Bird
0
0

Find the error in this PHP code snippet:

medium📝 Debug Q6 of 15
PHP - String Functions
Find the error in this PHP code snippet:
$str = "  Hello  ";
echo ltrim($str, " ");
Altrim() does not accept second argument
BThe function should be trim() instead of ltrim()
CThe second argument should be a string of characters to remove, not a space
DNo error, code works correctly
Step-by-Step Solution
Solution:
  1. Step 1: Check ltrim() function parameters

    ltrim() accepts a string and an optional character mask string to remove from the left side.
  2. Step 2: Analyze the code

    The second argument is a space character " ", which is valid to remove spaces from the left side.
  3. Final Answer:

    No error, code works correctly -> Option D
  4. Quick Check:

    ltrim() accepts second argument as chars to remove [OK]
Quick Trick: ltrim() second argument is chars to remove [OK]
Common Mistakes:
  • Thinking ltrim() cannot take second argument
  • Confusing character mask with boolean
  • Assuming trim() must be used always

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes