drxzpo70788179614 2010-11-26 14:50
浏览 19
已采纳

这些方法之间的性能差异

Is there any advantages/disadvantages to either of these statements over the other one:

<?php 
$test = 1;
$test2 = 2;
$test3 = $test + $test2;
echo "<p>Hello World</p>"; 
?>

OR

<?php 
$test = 1;
$test2 = 2;
$test3 = $test + $test2;
?>
<p>Hello World</p> 

What i'm asking is, if i'm outputting a page using PHP should i keep closing the php tags and stick normal HTML in or echo out the HTML? Which is better?

  • 写回答

5条回答 默认 最新

  • doume1301 2010-11-26 15:04
    关注

    if you want do be realy exact, there are three options:

    the slowest:

    echo "<p>Hello World</p>"; 
    

    a bit faster (no need to check for inline-valiables because of single quotes):

    echo '<p>Hello World</p>'; 
    

    the fastest (no php-interpreting at all):

    <p>Hello World</p>
    

    but between all of this, the difference would be so minimalistic that you won't ever notice it - much more important: make your code redable and do it the same way everywhere, so nobody who's reading your code (and has to maintain it) gets confused. i personally would prefer the third method (so i can use code-completition in my IDE), but it's your choice - i know a lot of people who output everything using echo.

    EDIT: to be complete, there are some more possibilitys i didn't mentioned like heredoc- and nowdoc-syntax, but this are basically the same as double/single-quotes... also, you could write print instead of echo and so on, but that wouldn't make a difference.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?