In this PHP tutorial, you shall learn how to append a string to the given string using String Concatenation Assignment Operator, with example programs.
PHP – Append String
To append string to another, in PHP, use string concatenation assignment operator. The concatenation assignment operator which is .=
appends the given string with a string.
To mention the operators separately, .
is concatenation operator and =
is assignment operator. .=
appends the left operand with the right side operand and assigns the result to the left operand.
The syntax to append string $string1
with the string $string2
is
$string1 .= $string2
Examples
1. Append string “banana” to the string “apple”
In the following program, we have defined two strings, namely $string1 and $string2. We will use string concatenation assignment operator and append $string2 to $string1.
PHP Program
<?php
$string1 = "apple";
$string2 = "banana";
$string1 .= $string2;
echo $string1;
?>
Output
Conclusion
In this PHP Tutorial, we learned how to append a string to given string, using example PHP program.