PHP: what is the difference between $varName = "$var \n"; from that with a period: $varName. = "$var \n"? quite confusing.
+1
A:
=
is for attributing a value
.=
is for concatenating
$var = "a";
$var = "b"; // $var will be "b";
$var = "a";
$var .= "b"; // $var will be "ab";
Timotei Dolean
2009-07-02 03:58:37
+10
A:
The . operator in PHP means concatenation.
You can use operators with the assignment operator (=) to accomplish both affects.
So these are the same:
$varname .= "stuff";
$varname = $varname . "stuff";
Which basically means, the original value plus the new value.
seanmonstar
2009-07-02 03:58:55
+3
A:
Also note that the same syntax applies to every mathematical operators such as + - / * %.
eg :
$i = 1;
$i += 1;
echo $i; // outputs 2
Sylvain
2009-07-02 04:08:04
A:
i believe it is just to append to the existing string. ie:
$str = "i went to";
$str .= "the park";
//$str will be "i went to the park"
Actually, $str will be "i went tothe park". You missed a space in there :-)
Sander Marechal
2009-07-02 07:08:39