Bird
0
0

Which of the following is a valid way to use echo to print multiple strings in PHP?

easy📝 Conceptual Q1 of 15
PHP - Output and String Handling
Which of the following is a valid way to use echo to print multiple strings in PHP?
Aecho "Hello" . " World!";
Becho ("Hello" + " World!");
Cecho "Hello", "World!";
Decho ["Hello", " World!"];
Step-by-Step Solution
Solution:
  1. Step 1: Understand string concatenation in PHP

    PHP uses the dot (.) operator to join strings together.
  2. Step 2: Analyze each option

    echo "Hello", "World!"; uses commas which echo supports but prints strings separately without concatenation. echo ("Hello" + " World!"); uses + which is invalid for strings in PHP. echo "Hello" . " World!"; correctly uses the dot operator to concatenate strings. echo ["Hello", " World!"]; tries to echo an array, which causes an error.
  3. Final Answer:

    echo "Hello" . " World!"; -> Option A
  4. Quick Check:

    String concatenation = dot operator [OK]
Quick Trick: Use dot (.) to join strings in echo [OK]
Common Mistakes:
  • Using + instead of . for string concatenation
  • Trying to echo arrays directly
  • Confusing commas with concatenation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes