Spaces When Concatenating Strings in PHP
Let two strings be stored in variables, and when concatenating them, we want to insert a space between them. This is done as follows:
<?php
$str1 = 'abc';
$str2 = 'def';
echo $str1 . ' ' . $str2; // outputs 'abc def'
?>
Let there be only one variable:
<?php
$str = 'abc';
echo $str . ' ' . 'def'; // outputs 'abc def'
?>
In this case, there is no point in выделять пробел, as a separate string - we can insert it as part of the second term:
<?php
$str = 'abc';
echo $str . ' def'; // outputs 'abc def'
?>
Create a variable with the text 'hello'
and a variable with the text 'world'
. Using
these variables and the string concatenation operation,
output the string 'hello world'
to the screen.