Bird
0
0

You want to create a full name string from $firstName and $lastName with a space between them. Which code correctly does this in PHP?

hard📝 Application Q15 of 15
PHP - Operators
You want to create a full name string from $firstName and $lastName with a space between them. Which code correctly does this in PHP?
A$fullName = $firstName . " " . $lastName;
B$fullName = $firstName + " " + $lastName;
C$fullName = $firstName . $lastName;
D$fullName = '$firstName $lastName';
Step-by-Step Solution
Solution:
  1. Step 1: Understand string concatenation with space

    To join first and last names with a space, you must add " " explicitly between them using dot operators.
  2. Step 2: Evaluate each option

    A misses the space, B uses + which is invalid for strings, D uses single quotes so variables are not interpolated.
  3. Final Answer:

    $fullName = $firstName . " " . $lastName; -> Option A
  4. Quick Check:

    Dot with space string joins names correctly [OK]
Quick Trick: Add space as " " between strings with dot [OK]
Common Mistakes:
  • Forgetting space between names
  • Using + instead of .
  • Assuming variables parse inside single quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes