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 \n"; ?> |
chevron_right
filter_none
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"; ?> |
chevron_right
filter_none
Output :
John Carter!
Code #3 :
<?php // First String $a = 'Hello'; // now $a contains "HelloWorld!" $a. = "World!"; // Print The String $a echo " $a \n"; ?> |
chevron_right
filter_none
Output :
HelloWorld!
Recommended Posts:
- Count of three non-overlapping sub-strings which on concatenation forms a palindrome
- Pairs whose concatenation contain all digits
- Print Concatenation of Zig-Zag String in 'n' Rows
- Lexicographical concatenation of all substrings of a string
- Number of pairs with Pandigital Concatenation
- Ropes Data Structure (Fast String Concatenation)
- Meta Strings (Check if two strings can become same after a swap in one string)
- Search in an array of strings where non-empty strings are sorted
- Number of common base strings for two strings
- Pairs of complete strings in two sets of strings
- Count of strings that become equal to one of the two strings after one removal
- Distinct strings such that they contains given strings as sub-sequences
- JavaScript | Replace multiple strings with multiple other strings
- PHP | Strings
- JavaScript | Strings
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




