Bird
0
0

Find the problem in this code snippet:

medium📝 Debug Q7 of 15
PHP - String Functions
Find the problem in this code snippet:
$text = "banana";
$newText = str_replace("a", "o");
echo $newText;
Aecho statement should use $text instead of $newText
Bstr_replace() cannot replace vowels
Cstr_replace() missing subject argument, so $newText is empty
DNo problem, output will be 'bonono'
Step-by-Step Solution
Solution:
  1. Step 1: Check str_replace() call

    It lacks the third argument (subject string), so it returns null or empty.
  2. Step 2: Understand effect on $newText

    $newText is assigned empty result, so echo outputs nothing.
  3. Final Answer:

    str_replace() missing subject argument, so $newText is empty -> Option C
  4. Quick Check:

    Missing subject causes empty result = str_replace() missing subject argument, so $newText is empty [OK]
Quick Trick: Always pass the string to modify as third parameter [OK]
Common Mistakes:
  • Forgetting subject string
  • Expecting automatic variable update
  • Using wrong variable in echo

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes