Concatenation of two strings in PHP program



To concatenate two strings in PHP, the code is as follows −

Example

 Live Demo

<?php
   $a = 1.967;
   $b = 1.969;
   $res = $a." and ".$b;
   echo " $res 
";    if((round($a, 2)) == (round($b, 2))) {       echo "
Both the values are equal!";    } else {       echo "
Both the values aren\'t equal";    } ?>

Output

This will produce the following output−

1.967 and 1.969
Both the values are equal!

Example

Let us now see another example −

 Live Demo

<?php
   $val1 = 'Jack';
   $val2 = 'Sparrow';
   echo "First Name = $val1 
";    echo "Second Name = $val2
";    $res = $val1.$val2;    echo "Concatenation = $res
"; ?>

Output

This will produce the following output−

First Name = Jack
Second Name = Sparrow
Concatenation = JackSparrow

Advertisements