Note that when using the . operator to concatenate strings, you need to wrap any variables in curly braces ({}) to avoid syntax errors:
xxxxxxxxxx
$name = "John";
$greeting = "Hello, {$name}!"; // use curly braces to include $name variable
echo $greeting; // output: "Hello, John!"
xxxxxxxxxx
<?php
$a = "Hello ";
$b = $a . "World!"; // now $b contains "Hello World!"
$a = "Hello ";
$a .= "World!"; // now $a contains "Hello World!"
?>
you can concatenate strings using the . (dot) operator or the .= (dot equals) operator to add to an existing string. Here's an example using the . operator:
xxxxxxxxxx
$name = "John";
$greeting = "Hello, " . $name . "!";
echo $greeting; // output: "Hello, John!"
Alternatively, you can use the .= operator to add to an existing string:
xxxxxxxxxx
$name = "John";
$greeting = "Hello, ";
$greeting .= $name;
$greeting .= "!";
echo $greeting; // output: "Hello, John!"