本文介绍了PHP中echo,echo(),print和print()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有几种方法可以用PHP打印输出。包括但不限于:

There are several ways to print output in PHP; including but not limited to:

echo 'Hello';
echo ('Hello');
print 'Hello';
print ('Hello');

这四个之间是否有区别?另外,括号根本没有区别吗?

Are there any differences between these four? Also, do the parentheses make any difference at all?

推荐答案

两个区别:

print 具有返回值(总是1),而 echo 没有。因此 print 可以用作表达式。

print has a return value (always 1), echo doesn't. Therefore print can be used as an expression.

echo 接受多个参数。因此,您可以编写 echo $ a,$ b 而不是 echo $ a。 $ b

echo accepts multiple arguments. So you may write echo $a, $b instead of echo $a . $b.

关于括号:在我眼中,它们只是错误。它们根本没有功能。你也可以写 echo((((((((((((((a [a))))))))))))$code>;人们通常会在无知中加上括号,以为 print 是一个函数。此外,它增加了误解的机会。例如 print( foo)&& print( bar)不打印 foobar ,因为PHP将此解释为 print(( foo)& ;& print( bar))。因此,即使外观不同,也会打印 bar1

Concerning the parentheses: They are simply wrong in my eyes. They have no function at all. You could as well write echo (((((((((($a)))))))))); people usually include parentheses from ignorance, thinking that print is a function. Furthermore it increases the chance of misinterpretation. For example print("foo") && print("bar") does not print foobar, because PHP interprets this as print(("foo") && print("bar")). So bar1 would be printed, even though it looks different.

这篇关于PHP中echo,echo(),print和print()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 07:54