'How to concat string in PHP [duplicate]
I want to do like this:
$string = "";
$string += "lol"; //maybe =+ > tried but both not working
But it isn't working, anyone suggestions? Google isn't making my life easy (cant search characters like = or +)
Solution 1:[1]
In PHP, string concatenation is done with the . operator:
$string .= 'lol';
+ is for addition.
Solution 2:[2]
$str = "";
while(...){
$str .= "lol.";
}
Replace the ellipses with your loop condition, (+=) is an addition assignment operator that adds the value of the right operand to a variable and assigns the result to the variable.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Marc B |
| Solution 2 |
