Bird
0
0

You want to print a variable and a string together in PHP. Which code correctly prints the variable $name followed by " is awesome"?

hard📝 Application Q8 of 15
PHP - Output and String Handling
You want to print a variable and a string together in PHP. Which code correctly prints the variable $name followed by " is awesome"?
Aprint $name . " is awesome";
Bprint "$name", " is awesome";
Cprint '$name is awesome';
DAll of the above
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable interpolation

    Double quotes allow variable interpolation, but only if variable is directly inside.
  2. Step 2: Check each option

    print $name . " is awesome"; concatenates variable and string correctly. print "$name", " is awesome"; uses commas (print takes one argument only). print '$name is awesome'; prints literal text with no variable expansion.
  3. Final Answer:

    print $name . " is awesome"; -> Option A
  4. Quick Check:

    Concatenate variable and string explicitly = D [OK]
Quick Trick: Use dot to join variable and string for safe output [OK]
Common Mistakes:
  • Using single quotes expecting variable expansion
  • Assuming double quotes always work without syntax
  • Not concatenating properly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes