Concatenate Strings

String concatenation is used to join two or more strings together into a single string. PHP provides the dot operator (.) for this purpose.

Example
<!DOCTYPE html>
<html>
<body>
<?php
$firstName = "John";
$lastName = "Doe";
// Concatenate strings using the . operator
$fullName = $firstName . " " . $lastName;
echo $fullName; // Outputs: John Doe
?>
</body>
</html>

Try it yourself

An easier and better way is by using the power of double quotes.


By surrounding the two variables in double quotes with a white space between them, the white space will also be present in the result:

Example
<!DOCTYPE html>
<html>
<body>
<?php
$x = "Hello";
$y = "World";
$z = "$x $y";
echo $z;
?>
</body>
</html>

Try it yourself


Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.