FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


[PHP] n00b question





n0obie4life
What's the difference if I use

Code:
$var .=
and
Code:
$var =


or is there no difference?
Chris Tiaens
I don't know if there is any difference, but I always use
Code:
$var =
and it seems to work properly...
Summer
Yeah and I never seen $var .= ...
Stubru Freak
http://www.php.net/manual/en/language.operators.assignment.php

Code:
<?php

$a = 3;
$a += 5; // sets $a to 8, as if we had said: $a = $a + 5;
$b = "Hello ";
$b .= "There!"; // sets $b to "Hello There!", just like $b = $b . "There!";

?>


So there's no difference if you didn't assign a value to the variable before.
mathiaus
I'll try and explain

$var = 1;
That sets the value of var as 1
$var = 5;
var now has the value of 5 instead of 1. If instead I had used
$var .= 5;
The var would now hold the value of 15. Basiclly ...

=
This sets a value to some thing. It means equal to

.=
This adds to the value. It means ALSO equal to
SystemWisdom
Just for clarification, it is called the "Concatenation Operator" and it is used to concatenate (or append) two strings into one.
Rhysige
And an example of use is in page displays Smile I use it when im echoing out a few different things from a function you can just have the return be one variable and have a different value depending on whats happened in the function.
n0obie4life
Summer wrote:
Yeah and I never seen $var .= ...


You must seldom stare into phpBB's code Smile.

@ SystemWisdom, mathiaus, Stubru Freak

Thanks for explaining it Smile.

I get it now.

-close-
Related topics
PHP-Nuke.. help!
php nuke question
PHP Editing Question
PHP magic_quotes_gpc question
Please help with php-quick question
php, css question (wordpress)
Question for any guitar players out there.
php/sql question
The last foolish PHP/MySQL Question of the Year....
PHP MySQL Question
PHP OCI8 question
PHP Form Question
phpBB 3 RC5 very basic/n00b question
Newbie PHP/MySQL question
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.