How to Concatenate two or more string in PHP

0
132

Welcome back to shortlearner.com, today we will see How to Concatenate two or more string in PHP.

How to Concatenate two or more string in PHP
each and every language has their different way to works with strings, in below example we concatenate two strings using php with the help of concatenation operator(“.”)

there is an another way to append a string in PHP.

By using Concatenation assignment operator(.=) we can append a string with another string.

<?php
$string1="Hello";
$string2="World !!";
$string3=$string1.$string2;
echo $string3;
?>

Output : HelloWorld !!

in this output  we concatinate two strings, but there is no space between the strings.
now we add space between two strings.

<?php
$string1="Hello";
$string2="World !!";
$string3=$string1." ".$string2;
echo $string3;
?>

Output : Hello World !!
Now we concatinate more than two strings.

<?php
$string1="Welcome to";
$string2="Shortlearner";
$string3="PHP Blog";
$string4=$string1.$string2.$string3;
echo $string4;
?>

Output : Welcome to Shortlearner PHP Blog