How To Prepend a String in PHP

How To Prepend a String in PHP

In this tutorial we will learn How To Prepend a String in PHP. We can use PHP concatenation operator or dot operator to prepend a string in PHP.

Using Concatenation Operator (.)

We can simply use Concatenation Operator (.) to Prepend a string in PHP.

No need to use any function or method for this.

Take a look at the code given below.

<?php
$string1 = 'Hello';
$string2 = 'World!';
$newString = $string1 . $string2;
?>

This will simply prepend a string with other one but without space obviously.

To add space between two strings we can do something like this.

<?php
$string1 = 'Hello';
$string2 = 'World!';
$newString = $string1 . ' ' . $string2;
?>

Demo

Comments

Popular posts from this blog

Gove confirms mandatory housebuilding targets for councils will be abolished in face of Tory rebellion – UK politics live

Kotak Mahindra Bank Recruitment 2022 Released for Graduate Candidates And Apply Online