Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Concatenation of two strings in PHP

  • Difficulty Level : Basic
  • Last Updated : 31 Jul, 2021

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 :

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

In case you wish to attend live classes with experts, please refer DSA Live Classes for Working Professionals and Competitive Programming Live for Students.

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 \n";
?>

Output :

 HelloWorld!

 
Code #2 :




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

Output :

John Carter!

 
Code #3 :




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

Output :

 HelloWorld!

PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples.




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!