This article已經探討過這個問題,以更大的深度比你甚至可能已經知道是可能的。
來自:http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40
1.
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.
2.
Expression. print() behaves like a function in that you can do: $ret = print "Hello World"; And $ret will be 1. That means that print can be used as part of a more complex expression where echo cannot. An example from the PHP Manual:
$b ? print "true" : print "false";
打印也是其它需要的,如果它是要內的使用的優先順序表的一部分複雜的表達。它只是在優先級列表的底部。只有「,」AND,OR和XOR較低。
- 參數(一個或多個)。語法是:echo expression [,expression [,expression] ...]但是echo(expression,expression)無效。這將是有效的:echo(「howdy」),(「partner」);相同:echo「howdy」,「夥伴」; (把括號放在這個簡單的例子中是沒有用的,因爲沒有像這樣的單個術語的運算符優先級問題。)
因此,回聲不帶括號可以採取多種參數,其中獲得級聯:
echo "and a ", 1, 2, 3; // comma-separated without parentheses
echo ("and a 123"); // just one parameter with parentheses
打印()只能取一個參數:
print ("and a 123");
print "and a 123";
因爲`echo`沒有返回值 – Mchl 2011-01-14 18:32:40