Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder Apothem's Avatar
    Join Date
    Mar 2008
    Thanked 25 Times in 25 Posts

    Which is faster?

    PHP Code:
    <?php $var "hi"; echo $var?>
    PHP Code:
    <?php $var "hi"?> <?php echo $var?>
    PHP Code:
    "hi"?><?=$var ?>

    To add to it, how come if there are no syntaxes following the last function, it can ignore a ;?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,662 Times in 2,631 Posts
    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
    Last edited by Fou-Lu; 07-14-2008 at 08:58 AM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts