2

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Bhupi
  • 2,928
  • 6
  • 34
  • 51
  • *(related)* [What does that symbol mean in PHP](http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php) – Gordon Jun 25 '11 at 09:31
  • 1
    http://php.net/manual/en/language.operators.string.php –  Jun 25 '11 at 09:24

3 Answers3

11

You are searching for .=:

$str = "";
$str .= "some value";
Floern
  • 33,559
  • 24
  • 104
  • 119
2
 $str .= "some value"; 
 $str .= "some more values";
Rajasekar Gunasekaran
  • 1,799
  • 3
  • 24
  • 40
0

Either:

$str = $str + "stuff";

Or:

$str .= "stuffsicles";
Mina
  • 610
  • 7
  • 21