- PHP

How to join two strings in PHP?

The easiest, and, in most cases, the best way is to use concatenation.

Use . and .= operators.

Example 1:

Combine two strings in echo with ..

<?php

$string1 = 'Hello ';
$string2 = 'World!';

echo $string1 . $string2;

?>

Output: Hello World!

Example 2:

Merge two string using .=.

<?php

$string = "My name is";
$string2 = ' Adam';

$string .= $string2;

echo $string;

?>

Output: My name is Adam