Concatenating PHP Strings

PHP provides several ways to concatenate strings, including the dot (.) operator and the concatenation assignment operator (.).

Example of Concatenating PHP Strings

<?php
$string1 = 'Hello, ';
$string2 = 'World!';

echo $string1 . $string2 . "\n";
// Outputs: Hello, World!
$string1 .= $string2;

echo $string1 . "\n";
// Outputs: Hello, World!
?>

Output:

Hello, World!
Hello, World!

Explanation: This example demonstrates the use of the dot (.) operator and the concatenation assignment operator (.=) to concatenate strings in PHP.