PHP - Output and String HandlingWhy do escape sequences like \n and \t only work inside double-quoted strings in PHP and not single-quoted strings?ABecause single quotes are deprecated in PHPBBecause single-quoted strings treat backslash literally except for \' and \\CBecause double quotes are faster to processDBecause escape sequences are only valid in heredoc syntaxCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand PHP string parsing rulesSingle-quoted strings treat most backslashes literally except for escaping single quote and backslash itself.Step 2: Reason why escape sequences don't work in single quotesEscape sequences like \n and \t are only parsed inside double-quoted strings.Final Answer:Because single-quoted strings treat backslash literally except for \' and \\ -> Option BQuick Check:Escape sequences only parsed in double quotes [OK]Quick Trick: Escape sequences only work in double-quoted strings [OK]Common Mistakes:Thinking single quotes parse escapesBelieving single quotes are deprecatedConfusing heredoc with single quotes
Master "Output and String Handling" in PHP9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PHP Quizzes Arrays - Multidimensional arrays - Quiz 14medium Arrays - Array search functions - Quiz 10hard Conditional Statements - Switch statement execution - Quiz 12easy Operators - Why operators matter - Quiz 10hard Output and String Handling - Printf and sprintf formatting - Quiz 11easy Output and String Handling - String interpolation in double quotes - Quiz 15hard PHP Basics and Execution Model - Comments in PHP - Quiz 13medium Type Handling - Type coercion in operations - Quiz 1easy Type Handling - Settype for changing types - Quiz 15hard Variables and Data Types - Variable declaration with dollar sign - Quiz 10hard