Follow
Follow

How to combine two strings in PHP

PHP Concatenation

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!
?>
Newsletter
Join Design Community
Get the latest updates, creative tips, and exclusive resources straight to your inbox. Let’s explore the future of design and innovation together.