How to use Concatenation operator in Php


In php Concatenation operator is used to combine two or more string value or float value or integer value or string and integer value or float and integer value. In php ( . ) dot sign used as concatenation operator to combine the two or more value. See the below examples

Example1
Lets take three variables containing some value
<!DOCTYPE html>
<html>
<head><title>expertcoding.com</title>
</head>
<body>
<?php
$a = "You are seeing";
$b = "the example of";
$c = "php Concatenation operator";
// now we want display all these value in a single sentence in browser using Concatenation operator
echo $a . " " .$b . " " . $c;
// here (" ") is used to provide white space 
?>
</body>
</html>

Example2
<!DOCTYPE html>
<html>
<head><title>expertcoding.com</title>
</head>
<body>
Ram brings 12 bananas worth Rs 50.5
Below are the several example for displaying the above sentence
<?php
echo "Ram brings 12 bananas worth Rs 50.5";
             //OR

echo "Ram brings" . " " . "12 bananas" . " " . "worth Rs" . " " . "50.5";
                 //OR
//  by assigning the value in variable
$a = "Ram brings";
$b = "12 bananas";
$c = "worth Rs";
$d = 50.5;
echo $a . " " .  $b . " " . $c . " " . $d;
                   //OR
echo $a . " " . "12 bananas" . " " . $c . " " . "50.5";
?>
</body>
</html>

No comments: