Forum Moderators: coopster

Message Too Old, No Replies

I do'n understand this

$x .= 'sum1';

         

electricocean

5:48 am on Jul 1, 2005 (gmt 0)

10+ Year Member



Hey. I don't understand it when people write $x .= 'sum1'; or before the '=' sign.

Can someone explain this to me?

thanks,
electricocean

sabongio

5:55 am on Jul 1, 2005 (gmt 0)

10+ Year Member



.= adds to the end of a string while = overwrites the string.

dreamcatcher

6:59 am on Jul 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



electricocean, the period is for whats called concatenation. Its used for joining two string together as sabongio mentioned.

Example:

$string1 = "Hello";
$string1 .= " World";

echo $string1;

This would output "Hello World";

Its useful if you need to loop and build string data. If no concatenation is in place, again as sabongio mentioned, it will over write your existing data.

$string1 = "Hello";
$string1 = "World";

echo $string1;

This would output "World";

Hope that helps.

dc

electricocean

5:28 pm on Jul 3, 2005 (gmt 0)

10+ Year Member



Thanks, that helps a lot. Are there any others like that? I thought I saw '+=' somewhere.

Thanks,
electricocean

ergophobe

6:03 pm on Jul 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can combine all "binary" arithmetic and string operators (that helped didn't it?) In plainer English, that means that you can combine the "=" with +-*/.% and all of the bitwise operators.

$a=3;
$a *= 5;
echo $a;

> 15

To get the full scoop, read
[docs.php.net...]

It might take you a few times through it for some concepts, but perservere!

mcibor

8:02 pm on Jul 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A structure

$var1 (sth)= $var2; is the same as
$var1 = $var1 (sth) $var2;

Therefore
$a = $a + 2; => $a += 2;
$a = $a . "bla bla"; => $a .= "bla bla";
etc.

have a good time learning php!
Michal Cibor