There are two
String operators in PHP.
1. Concatenation Operator "." (dot)
2. Concatenation Assignment Operator ".=" (dot equals)
Concatenation Operator
Concatenation is the operation of joining two character strings/variables together.
In PHP we use . (dot) to join two strings or variables.
Below are some examples of string concatenation:
<?php
echo "Hello "."there!";
echo "My"." "."name"."is"." "."Mike";
?>
Output
Hello there!
My name is Mike
Below are some examples of string concatenation including variables:
<?php
$message = "Hello there!";
$name = "Mike";
$age = 19;
echo $message;
echo "My name is ".$name;
echo "I am ".$age;
?>
Output
Hello there!
My name is Mike
I am 19
Concatenation Assignment Operator (.=)
Example :
<?php
$message = "Hello";
echo $message.=" there!"; //is same as $message = $message ." there!"
?>
Output
Hello there!