We can use the PHP concatenation operator (.) to join or combine two strings together in PHP. This operator is exactly designed for strings.

There are two string operators :

  • Concatenation operator (‘.’) – Concatenation of str1 and str2

Example: $str1 . $str2

  • Concatenating assignment operator (‘.=’) Appends the str2 to the str1

Example:  $str1 .= $str2

<?php
$str1 = 'PHP';
$str2 = 'Tutorials!';
$str = $str1 . ' ' . $str2;
echo $str; // Output: PHP Tutorials!
?>

Categorized in: