http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40What is the difference between echo and print? Which is faster, echo or print? Feb 3rd, 2004 08:20geozipp, Nathan Wallace Rasmus LerdorfThere is a difference between the two, but speed-wise it should be irrelevant which one you use. print() behaves like a function in that you can do: $ret = print "Hello World";And $ret will be 1That means that print can be used as part of a more complex expression where echo cannot. print is also part of the precedence table which it needs to be if it is to be used within a complex expression. It is just about at the bottom of the precendence list though. Only "," AND, OR and XOR are lower.echo is marginally faster since it doesn't set a return value if you really want to get down to the nitty gritty.If the grammar is: echo expression [, expression[, expression] ... ]Then echo ( expression, expression ) is not valid. ( expression ) reduces to just an expression so this would be valid: echo ("howdy"),("partner");but you would simply write this as: echo "howdy","partner"; if you wanted to use two expression. Putting the brackets (which are parentheses, not brackets) in there serves no purpose since there is no operator precendence issue with a single expression like that.
但是print是按格式输出,而echo 是直接输出,就想当于输出一个字符串,有点类于print的特殊形式
2.print的速度要比echo 快一些,这些可以自己测试一下.
Which is faster, echo or print?
Feb 3rd, 2004 08:20geozipp, Nathan Wallace
Rasmus LerdorfThere is a difference between the two, but speed-wise it
should be irrelevant which one you use. print() behaves
like a function in that you can do: $ret = print "Hello World";And $ret will be 1That means that print can be used as part of a more complex
expression where echo cannot. print is also part of the
precedence table which it needs to be if it is to be used
within a complex expression. It is just about at the bottom
of the precendence list though. Only "," AND, OR and XOR
are lower.echo is marginally faster since it doesn't set a return
value if you really want to get down to the nitty gritty.If the grammar is: echo expression [, expression[, expression] ... ]Then echo ( expression, expression ) is not valid. ( expression ) reduces to just an expression
so this would be valid: echo ("howdy"),("partner");but you would simply write this as: echo "howdy","partner"; if you wanted to use two expression. Putting the brackets (which are
parentheses, not brackets) in there serves no
purpose since there is no operator
precendence issue with a single expression like that.