PHP Concatenate String

PHP Concatenate:

PHP also has a unique style to make a Concatenation. Most of the languages are using plus sign , but PHP is using dot i.e. (.) sign .  Remember every mathematical options will be handled by only plus sign  and to make an addition of two or more strings use (.) dot operation.
Sample Code 1 :

<?php
$FirstName = "Michale";
$LastName = "Bode";
$FullName=$FirstName." ".$LastName;
echo $FullName;
?>

Outputs: Michale Bode

Sample Code 2:
<?php
$CarName = "BMW";
$Color = "White";
$info="My ".$CarName. " car color is ".$Color."!";
echo $info;
?>
Output : My BMW car color is White!

Sample Code 3:
<?php

$BMWCount1=2;
$AUDICount2=5;

$CarName1 = "BMW";
$CarName2 = "Audi";
$info="We have ".$CarName1. " and ".$CarName2." for sale. There are total ".$BMWCount1+$AUDICount2." cars for sale." ;
echo $info;
?>
Output : We have BMW and Audi for sale. There are total 7 cars for sale.


No comments :

Post a Comment

Leave A Comment...