There’s no exact function to append a string in PHP. But PHP concatenation assignment operator (.=) is used to append a string with another string.

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";
$str1 .= " Tutorials!";
echo $str1; // Outputs: PHP Tutorials!
?>

Categorized in: