String Operators
Explore how to join strings in PHP using the dot operator for concatenation and the concatenation assignment operator. Understand the practical differences and applications to manipulate text efficiently in your PHP programs.
We'll cover the following...
In PHP, you can concatenate one string with another using the dot (.) operator.
There are only two string operators:
- Concatenation (
.): - Concatenation Assignment (
.=)
Concatenation
The most important operation in strings is concatenation. It means joining one string to another. For instance, the concatenation of water and bottle will result in a string waterbottle.
Run the code below to see how this is done:
Concatenation Assignment
Concatenation assignment is a slight variation of concatenation where you concatenate (add) one string at the end of another without the need for a third destination string. The difference between concatenation and concatenation assignment is similar to + and +=.
Run the code below to see how this works:
In the next lesson, we will discuss in built functions for performing string operations.