Search code examples
phpstringstring-concatenation

How can I use the += operator in PHP for a string?


How can I use the += operator for a string in PHP?

Below is a Java example:

String str = "";

str += "some value";
str += "some more values";

The above example concatenates and assign all values to the str object.

How can I achieve this in PHP?


Solution

  • You are searching for .=:

    $str = "";
    $str .= "some value";