Last updated on August 24, 2023
The concatenation operator (‘.’) is mostly used in PHP to concatenate the strings. We can concatenate any kind of value through the concatenation operator.
Example 1:
Let’s concatenate the string.
"John Smith";
" is Software Engineer";
In this example, we have two strings that need to be concatenated. To concatenate them we can use the concatenation operator (‘.’).
echo "John Smith" . " is Software Engineer";
// Output: John Smith is Software Engineer
Above we concatenated both strings without using any variable. In the next example, we will be storing both strings in the variable and concatenating them through the concatenation operator (‘.’).
Example 2:
Let’s store both strings into the variables and then concatenate them.
$name = "John Smith";
$profession = " is Software Engineer";
In this example, we have two variables $name and $profession that store two different strings. To concatenate them, we are using the concatenation operator.
echo $name . $profession;
// Output: John Smith is Software Engineer