PHP中的“打印"和“回显"之间有什么区别吗? [英] Is there any difference between 'print' and 'echo' in PHP?
问题描述
可能重复:
PHP中的echo和print有何不同?
Possible Duplicate:
How are echo and print different in PHP?
更新:
我发现确切 重复(当我初次输入此问题时并没有出现,而是通过... google找到的): 请投票给我以结束这个问题,因为它很累,请去追捕另一个可怜的人;-)
I found to my relief an exact duplicate (it wasn't showing up when I typed this question at first, I found it with ... google): Please vote with me to close this question, because it's tiring, go hunt that other poor guy a bit ;-)
PHP中的print
和echo
之间是否有区别?如果是这样,我应该在什么时候使用?如果没有,为什么会有两个关键字?
Is there any difference between print
and echo
in PHP? If so, which should I use and when? If not, why are there two keywords?
更新:
不满意者:请阅读SO常见问题解答.因此还设置了捕获谷歌问题.所以您不应该为此投票,这个问题是一个有效的问题,已经在很多地方都得到了解答,现在也是如此.
At the downvoters : please read the SO faq. SO was setup also to capture googleable questions. so you shouldn't downvote for that, this question is a valid question, answered on a lot of places and now on SO too.
您当然可以出于其他原因拒绝投票,但请在以下各行中发表评论 -1:已投票赞成..,因为目前,我不了解该投票赞成.
Of course you can downvote for another reason, but please leave a comment in the lines of -1 : downvoted for .. , cause for now, I'm not understanding the downvotes.
推荐答案
来自用于echo()
函数的PHP手册建议的此链接:
From this link, suggested by the PHP manual entry for the echo()
function:
-
速度.两者之间是有区别的,但是在速度上是有区别的 应该与你哪一个无关 使用.回声速度稍快,因为 如果您没有设置返回值 真的很想了解细节 坚韧不拔.
Speed. There is a difference between the two, but speed-wise it should be irrelevant which one you use. echo is marginally faster since it doesn't set a return value if you really want to get down to the nitty gritty.
表达. print()的行为类似于一个函数,您可以执行以下操作:$ ret = 打印"Hello World"; $ ret将是
Expression. print() behaves like a function in that you can do: $ret = print "Hello World"; And $ret will be
这意味着可以将print用作更复杂的表达式的一部分 回声不能的地方.来自的例子 PHP手册:
That means that print can be used as part of a more complex expression where echo cannot. An example from the PHP Manual:
$ b?打印"true":打印"false";
$b ? print "true" : print "false";
打印也是优先事项的一部分 如果是的话需要的表 在一个综合体中使用 表达.就在 但是优先级列表的底部. 只有," AND,OR和XOR较低.
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 precedence list though. Only "," AND, OR and XOR are lower.
- 参数.语法为:echo expression [,expression [,expression]
...]但是echo(表达式,
表达式)无效.这个会
有效:echo("howdy"),("partner");
与:echo"howdy","partner";
(将括号放到这样简单的位置 这个例子没有用,因为那里 是没有运算符优先级问题的 这样的单字.)
- Parameter(s). The grammar is: echo expression [, expression[, expression]
... ] But echo ( expression,
expression ) is not valid. This would
be valid: echo ("howdy"),("partner");
the same as: echo "howdy","partner";
(Putting the brackets in that simple example serves no purpose since there is no operator precedence issue with a single term like that.)
因此,不带括号的回声可能会占用 多个参数 串联:
So, echo without parentheses can take multiple parameters, which get concatenated:
echo和一个",1,2,3; //
逗号分隔,不带括号
回声(和123"); //只有一个
带括号的参数
echo "and a ", 1, 2, 3; //
comma-separated without parentheses
echo ("and a 123"); // just one
parameter with parentheses
print()只能使用一个参数:
print() can only take one parameter:
print(和123");打印和 一个123;
print ("and a 123"); print "and a 123";
这篇关于PHP中的“打印"和“回显"之间有什么区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!