07-14-2008, 06:29 AM
<?php $var = "hi"; echo $var; ?>
<?php $var = "hi"; ?> <?php echo $var; ?>
$var = "hi"; ?><?=$var ?>
To add to it, how come if there are no syntaxes following the last function, it can ignore a ;?
07-14-2008, 07:34 AM
I haven't tested any of the above, but I would suspect the first would be the fastest. Think of a light switch, it takes more energy to turn the light on than off than on again, than it does to leave it on for 10 minutes. The last two are like telling the processor you're all done, than changing you're mind and starting again. I mean, I haven't tested anything, but I would assume that the last two would be slower.
As for the <?=, I'm trying to find reference for it. I don't use any short tag style, but my understanding is <?= is an evaluative syntax, so you are only allowed one value to start with - meaning no semi-colon required. As soon as I finish this FFT battle, I'll see if I can't find the reference for it on the php site.
Ah here we go: http://ca3.php.net/manual/en/language.basic-syntax.php. Its listed in example #2. I was close, <?= $var ?> is the exact same as <? echo $var; ?>, so it doesn't take just any expression - only something you want to output. I was right that it only takes the one value though :D