about $message .= "xxx";

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hunterhp
Forum Commoner
Posts: 46
Joined: Sat Jan 22, 2005 5:20 pm
Contact:

about $message .= "xxx";

Post by hunterhp »

I know that what .= does, but does it improve performance/speed?

I mean, can't you just do

$message = "<html>
<head>
ect ect";

instead of

$message = "<html>";
$message .= "<head>";
$message .= "ect ect";

What's the difference, and which is better/more user-end friendly?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

It's generally used in this scenario.

Code: Select all

$message .= 'Hello';

if (isset($somevar))
&#123;
     $message .= ' And Salutations';
&#125;

$message .= ' And Googbye';
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

its the same thing...

its more coder friendly if you use it like you have in your post. its used so you can see what you putting in there better or if you have a situation like this

Code: Select all

$message = 'Hi, ';

if($name == '*PrObLeM*') &#123;
$message .= "PrObleM you are a god amongst men ";
&#125; else &#123;
$message .= "who the hell are you?";
&#125;

$message .= ' oh and have a nice day';
the output would be:

If you're me: Hi, PrObleM you are a god amongst men oh and have a nice day.

if you're not me: Hi, who the hell are you? oh and have a nice day.
Post Reply