PHP Concatenate String and Variable
Learn what is concatenate operator is in php and how we concatenate strings and variables. PHP supports string concatenate, variable as well as array concatenation. Comma sign “,” denotes the javascript concatenate operator similarly “.” dot symbol denotes PHP concatenate operator. The concatenation operator is going to convert the left-hand side and right-hand side operands to string format. If already they are in string format, it just combines them together. For example, see the below example.
Ex:
<?php
echo "wonder" . "develop"; //wonderdevelop
?>
Here, the words are already in string format, so the concatenate operator combines the strings together.
Ex:
<?php
echo "Wonder" . "7"; //Wonder7
?>
Here, we have a string and an integer. When we use concatenate operator between this type of datatypes. First integer “7” will convert into string, then both strings are combined together.
Variable Concatenation
<?php
$name1 = "Wonder";
$name2 = "Develop";
echo $name1 . $name2; //WonderDevelop
?>
Here, we have two variables called name1 and name2. We can concatenate these variables using concatenate operator.