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,030
  • 21
  • 100
  • 124
Bhupi
  • 2,808
  • 6
  • 32
  • 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

10

You are searching for .=:

$str = "";
$str .= "some value";
Floern
  • 32,709
  • 24
  • 103
  • 117
2
 $str .= "some value"; 
 $str .= "some more values";
Rajasekar Gunasekaran
  • 1,740
  • 3
  • 23
  • 38
0

Either:

$str = $str + "stuff";

Or:

$str .= "stuffsicles";
Mina
  • 509
  • 5
  • 21