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
<?php
$a = 'Hello' ;
$b = 'World!' ;
$c = $a . $b ;
echo " $c \n" ;
?>
|
Time complexity : O(n)
Auxiliary Space : O(n)
Code #2 :
PHP
<?php
$fname = 'John' ;
$lname = 'Carter!' ;
$c = $fname . " " . $lname ;
echo " $c \n" ;
?>
|
Time complexity : O(n)
Auxiliary Space : O(n)
Code #3 :
PHP
<?php
$a = 'Hello' ;
$a .= " World!" ;
echo " $a \n" ;
?>
|
Time complexity : O(n)
Auxiliary Space : O(n)
Code #4 :
PHP
<?php
$a = 'Geeksfor' ;
$b = "Geeks" ;
$c = "$a{$b}" ;
echo " $c \n" ;
?>
|
Output
GeeksforGeeks
Time complexity : O(n)
Auxiliary Space : O(n)
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.
Last Updated :
27 Jan, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...