How to combine two strings in PHP

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!
?>

Praveen Kumar

I am a fullstack web developer with a passion for SEO, creating stunning websites, and organic marketing. I am a perfectionist.

Post navigation