PHP - Concatenate Strings

In PHP, you can concatenate (combine) strings using the dot (.) operator.

Example:

<?php $firstName = "John"; $lastName = "Doe"; $fullName = $firstName . " " . $lastName; echo $fullName; // Outputs: John Doe ?>

Notes:

  • The . operator joins two strings together.

  • If you want to append a string to an existing variable, you can use .=:

<?php $message = "Hello"; $message .= " World!"; echo $message; // Outputs: Hello World! ?>