PHP: String operators

This entry is part 17 of 54 in the series PHP Tutorial

Earlier, we have used .(dot) to join 2 strings together.


$text1 = 'Hello ';
$text2 = $text1 . 'World!'; 

echo "$text2";
echo "\n";

$text3 = 'Upwhere We ';
$text3 .= 'Belong!';  

echo "$text3";
echo "\n";

$num = 3;

echo "Result: " . ($num + 3); 


In the statement $text3 .= ‘Belong!’, the .(dot) here is a unary string operator.

The statement here will add ‘Belong!’ to variable $text3 itself.

Series Navigation<< PHP: $_POST
PHP: Creating multiline strings using heredoc <<< >>

Leave a comment

Leave a Reply