Re: echo or print ?

From: Date: Sat, 21 Apr 2007 11:52:34 +0000
Subject: Re: echo or print ?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-253422@lists.php.net to get a copy of this message
On 4/18/07, Richard Lynch <ceo@l-i-e.com> wrote:
On Tue, April 17, 2007 1:40 am, Christian Haensel wrote: Whenever I see people put their code up for review, I realize they mostly use print instead of echo, while I am using echo 99% of the time. Actually, I can't even remember when I last used the regular print. There used to be a difference, but not really any more, I don't think. Or does print still not allow multiple arguments?... What do you guys use, and what is the advantage (if ther is any) of print over echo? And I am not talking about print_r or anything, just the regular print. :o) I use echo, because I'm old, and got in the habit, back when print() was a function and echo was a language construct, and only echo let you have as many args with commas as you wanted. But there's no significant difference, as far as I know.
There is a difference, echo is slightly faster. code used for benchmark: <? $start = microtime(TRUE); for ($i=0; $i<100000; ++$i) { print "ABC"; } echo sprintf("With print ($i): %0.3f\n",microtime(TRUE) - $start); $start = microtime(TRUE); for ($i=0; $i<100000; ++$i) { echo "ABC"; } echo sprintf("With echo ($i): %0.3f\n",microtime(TRUE) - $start); ?> it displays 100000 times ABC, first with the print command, and second with the echo command. Result: ABCABCABC<snip> print (100000): 0.085 ABCABCABC<snip> echo (100000): 0.076 It's not a lot, but since we are displaying data a lot, (most used function?) it will make a difference in really big scripts. Tijnema


« previous php.general (#253422) next »