Skip to content

PHP String Concatenation

Syntax

In PHP, the concatenation operator (.) is used to combine two or more strings into one.

$combinedString = $string1 . $string2; // Using the . operator
$string1 .= $string2;

Example

// Concatenating strings
$firstName = "John";
$lastName = "Doe";
$fullName = $firstName . " " . $lastName;
// Appending to a string
$greeting = "Hello";
$greeting .= ", World!"; // Equivalent to $greeting = $greeting . ", World!";