String operators are used to work with strings in PHP. They help in joining text values. They do not store data by themselves — storing is done by the assignment operator. A string operator only joins two or more strings. It works on all sizes of strings, small or big.
There are two types of string operators, as described below:
1. (Concatenation Operator):
The symbol of this operator is . (dot), which joins two strings. It combines two strings into a single string, and PHP creates a new string for this.
string1 . string2;
<?php
$first = "www.";
$second = "edutation.com";
$result = $first . $second;
?>
www.edutation.com
2. .= (Concatenation Assignment Operator):
The symbol of this operator is .=. It performs two tasks at the same time: first, it concatenates, and second, it assigns — meaning it joins two words and also assigns (stores) the value into the same variable.
variable .= value;
<?php
$site = "www.";
$site .= "edutation.com";
?>
www.edutation.com
