We have given two strings and the task is to append a string str1 with another string str2 in PHP. There is no specific function to append a string in PHP. In order to do this task, we have the this operator in PHP:
Using Concatenation assignment operator (“.=”): The Concatenation assignment operator is used to append a string str1 with another string str2.
Syntax:
$x .= $y
Example :
PHP
<?php
function append_string ( $str1 , $str2 ) {
$str1 .= $str2 ;
return $str1 ;
}
$str1 = "Geeks" ;
$str2 = "for" ;
$str3 = "Geeks" ;
$str = append_string ( $str1 , $str2 );
$str = append_string ( $str , $str3 );
echo $str ;
?>
|
Using Concatenation Operator(“.”): The Concatenation operator is used to append a string str1 with another string str2 by concatenation of str1 and str2.
Syntax:
$x . $y
Example :
PHP
<?php
function append_string ( $str1 , $str2 ){
$str = $str1 . $str2 ;
return $str ;
}
$str1 = "Geeks" ;
$str2 = "for" ;
$str3 = "Geeks" ;
$str = append_string ( $str1 , $str2 );
$str = append_string ( $str , $str3 );
echo $str ;
?>
|