Tutorialspoint.dev

Concatenation of two strings in PHP

There are two string operators. The first is the concatenation operator (‘.‘), which returns the concatenation of its right and left arguments. The second is the concatenating assignment operator (‘.=‘), which appends the argument on the right side to the argument on the left side.

Examples :

Input : string1:  Hello
        string2 : World! 
Output : HelloWorld!


Input : string1: geeksfor
        string2: geeks
Output : geeksforgeeks

Code #1:

<?php
  
// First String
$a = 'Hello';
  
// Second String
$b = 'World!';
  
// Concatenation Of String
$c = $a.$b;
  
// print Concatenate String
echo " $c ";
?>

Output :

 HelloWorld!

 
Code #2 :



<?php
  
// First String
$fname = 'John';
  
// Second String
$lname = 'Carter!';
  
// Concatenation Of String
$c = $fname." ".$lname;
  
// print Concatenate String
echo " $c ";
?>

/div>

Output :

John Carter!

 
Code #3 :

<?php
  
// First String
$a = 'Hello';
  
// now $a contains "HelloWorld!"
$a. = "World!";
  
// Print The String $a
echo " $a ";
?>

Output :

 HelloWorld!


This article is attributed to GeeksforGeeks.org

You Might Also Like

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter