Concatenating two strings in PHP

Concatenating two strings in PHP

Right now, will figure out how to link two strings in PHP? Here, we have two strings and we need to link (include) them.

The server-side language of the web, PHP has a great deal of help with regards to a string. PHP has a wide scope of techniques and properties on string information type yet as a backend designer, fundamental string tasks ought to be consistently in the hand. String connection is an essential however valuable element of a programming language and in PHP we have the same ideas.

How about we take an example,

$string1 = "Hello World!";
$string2 = "My first program.";

Assume we have two strings. string1 and $string2. They contain a string value. Presently we need to connect them and make them a solitary string. We can do this in the following manners.

Making another connected string

Right now, will make another string that will contain both the strings joined in one string. This technique is valuable on the off chance that we would prefer not to alter the first strings. We utilize the. period sign for a link in PHP.

We can connect it as follows,

<?php
	$string1 = "Hello World!";
	$string2 = "My first program.";

	$output = $string1 . $string2;
	echo $output; //Hello World!My first program.
?>

This makes another string that contains both strings. Note that string1 is composed after string2 as we have done in the code and there is no space in the middle. Presently we can utilize the output string without altering the first strings.

Annexing after the first strings

<?php
	$string1 = "Hello World!";
	$string2 = "My first program.";

	$string1 = $string1 . $string2;
	echo $string1; //Hello World!My first program.
?>

We can likewise annex one string after another utilizing the equivalent. administrator. We need to do just,

This adds the string2 after string1, yet the outcome is the same. Notice that now the first string1 variable has changed.

So this is the way we can do string link in PHP. Offer your considerations in the remarks beneath.

Recent Posts

error: Alert: Content is protected!!