Bird
0
0

What is the output of the following PHP code?

medium📝 Predict Output Q13 of 15
PHP - Operators
What is the output of the following PHP code?
$greeting = "Hello";
$name = "Alice";
echo $greeting . ", " . $name . "!";
AHello,Alice!
BHello Alice!
CHello, Alice!
DHello . , . Alice . !
Step-by-Step Solution
Solution:
  1. Step 1: Analyze string concatenation

    The code joins "Hello", ", ", "Alice", and "!" using the dot operator.
  2. Step 2: Combine strings step-by-step

    "Hello" . ", " = "Hello, " and then "Hello, " . "Alice" = "Hello, Alice" and finally "Hello, Alice" . "!" = "Hello, Alice!"
  3. Final Answer:

    Hello, Alice! -> Option C
  4. Quick Check:

    Concatenate with dot = Hello, Alice! [OK]
Quick Trick: Dot joins strings exactly as written [OK]
Common Mistakes:
  • Missing spaces inside strings
  • Expecting plus (+) to work
  • Confusing output with literal dots

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes