PHP Concatination Strings


PHP Concatinating Strings

In PHP, concatination is the joining of strings. The easiest way to explain this process is through the following examples.With concatinatiion, two variables can be joined with a period inserted between them.

Example 1

$var1="My name is";
$var2="John";

echo $var1.$var2;
#Ouput is My name isJohn.
 

Example 2

$var1="My name is";
$var2=" "; //space
$var3="John";

echo $var1.$var2;
#Ouput is My name is John.

Example 3

$var1="My name is";
$var2="John";

echo $var1." ".$var2;
#Ouput is My name is John.

Notes:
With php, all text between quotes can be ended with a period. In example 3, a space was created after $var1. We simply used quotes to make a space.

Below, is the same as example 3 with the exception of using single quotes.

$var1="My name is";
$var2="John";

echo $var1.' '.$var2;
#Ouput is: My name is John.