Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

Concatenate Strings

String Concatenation

To concatenate or combine two strings, you can use the . operator:

Example

$x = "Hello";
$y = "World";
$z = $x . $y;
echo $z;

The result of the example above is “HelloWorld,” with no space between the two words.

You can add a space character like this:

Example

$x = "Hello";
$y = "World";
$z = $x . $y;
echo $z;

A simpler and more effective approach is to use double quotes.

By placing the two variables inside double quotes with a space between them, the space will be included in the result as well:

Example

$x = "Hello";
$y = "World";
$z = "$x $y";
echo $z;