The string operator, also known as the concatenation operator, allows us to join two strings together. Strings need to be joined for various reasons, such as injecting a variable, or even splitting a long string so that it’s more readable in your IDE.

Let’s take a look at the following sentence (string): “I am sick and tired of creating operator tutorials.” We can echo it out or assign it to a variable. We can also split the string up using the concatenation operator and have as many strings as there are characters in it.

<?php

echo "I am sick and tired of creating operator tutorials.";
echo "I am sick and " . "tired" . " of creating operator tutorials";
echo "2024 can't come soon enough. " . 
     "As soon as it does, I am " .
     "buying a GT-R.";
?>

One thing to note when you’re splitting a string: remember the spaces. Those can get lost really quickly.

<?php

echo "Hello" . "there"; // Hellothere
echo "Hello " . "there"; // Hello there
?>

#web-development #software-development #php #programming #computer-science #string

PHP 7.x — P20: String Operator
1.10 GEEK