PHP Variables doubt?
Posted in Help the coder! on Jul 2, 2009 at 10:13 IST (8 months ago). Subscribe to this post
Email
Showing comments 1 to 4 of total 4 on page 1 of 1
Post replyShowing comments 1 to 4 of total 4 on page 1 of 1
« Previous1Next »
kiddinkidRank: 34
What is the difference between $varName = "$var \n"; from that with a period: $varName. = "$var \n"? quite confusing.
Posted by kiddinkid on Thursday, July 2, 2009, 10:13 am
lemondri...Rank: 55
= is for attributing a value .= is for concatenating
$var = "a"; $var = "b"; // $var will be "b";
$var = "a"; $var .= "b"; // $var will be "ab";
Posted by lemondrizzle on Thursday, July 2, 2009, 12:24 pm
mindhackerRank: 38
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";
Posted by mindhacker on Thursday, July 2, 2009, 1:56 pm
rajkumar...Rank: 4
The first one is assigning a value to another variable.
The second one is used to concatenate strings. consider a scenario where you need to concatenate strings within a loop. This one is the best way to do so.
foreach(iteration)
{
$some_variable .= $some_other_variable .",";
}
output is like this : val1,val2,val3 etc..
Posted by rajkumar_pb on Wednesday, October 7, 2009, 2:49 am
Pages: « Previous1Next »