Bird
0
0

You want to print the following sentence exactly as it is, including the dollar sign:

hard📝 Application Q15 of 15
PHP - Output and String Handling
You want to print the following sentence exactly as it is, including the dollar sign:
The price's $price.
Which echo statement will produce this output correctly?
Aecho "The price's \$price.";
Becho 'The price's $price.';
Cecho "The price's $price.";
Decho 'The price's \$price.';
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable interpolation and escaping

    In double quotes, $ starts variable interpolation. To print a literal $, it must be escaped with a backslash (\$).
  2. Step 2: Analyze each option

    echo "The price's $price."; prints "The price's " followed by $price (undefined, empty), resulting in "The price's .". echo 'The price's $price.'; syntax error due to unescaped apostrophe in "price's". echo "The price's \$price."; escapes $ correctly in double quotes (apostrophe fine), printing exactly. echo 'The price's \$price.'; syntax error from unescaped apostrophe (backslash literal if fixed).
  3. Final Answer:

    echo "The price's \$price."; -> Option A
  4. Quick Check:

    Escape $ in double quotes with \$ [OK]
Quick Trick: Escape $ with \$ inside double quotes to print it [OK]
Common Mistakes:
  • Not escaping $ in double quotes
  • Using backslash in single quotes incorrectly
  • Syntax error with unescaped apostrophe in single quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes