PHP - String FunctionsWhy does str_replace() return the modified string instead of changing the original string variable directly?ABecause strings in PHP are immutable and functions return new stringsBBecause str_replace() modifies the original string by referenceCBecause PHP does not support string replacementDBecause str_replace() only works on arraysCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand PHP string behaviorStrings in PHP are immutable, meaning they cannot be changed after creation.Step 2: Explain function return behaviorFunctions like str_replace() return a new string with replacements; original string stays unchanged unless reassigned.Final Answer:Because strings in PHP are immutable and functions return new strings -> Option AQuick Check:Immutable strings = return new string [OK]Quick Trick: Assign str_replace() result to variable to keep changes [OK]Common Mistakes:Expecting in-place string changeThinking str_replace() modifies by referenceConfusing string and array behavior
Master "String Functions" in PHP9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PHP Quizzes Array Functions - Why array functions matter - Quiz 5medium Classes and Objects - Constants in classes - Quiz 3easy Classes and Objects - Why OOP is needed in PHP - Quiz 13medium Classes and Objects - Class declaration syntax - Quiz 8hard File Handling - JSON encoding and decoding - Quiz 6medium Inheritance and Polymorphism - Instanceof operator - Quiz 1easy Sessions and Cookies - Starting and using sessions - Quiz 12easy String Functions - String comparison functions - Quiz 9hard String Functions - String split and explode - Quiz 11easy Superglobals and Web Context - Form handling execution flow - Quiz 11easy