Home  >  Article  >  Backend Development  >  PHP的echo和print小谈

PHP的echo和print小谈

WBOY
WBOYOriginal
2016-06-23 14:32:03884browse

自学php快2个多月了。学着做点东西,基本函数用的还凑合,用help点开加search找。基本没问题
不过那个php主页的说明实在是很模糊,很多参数说完了还是看不懂,有实践才有真理。这点到哪里都没有错。

碰到最初的就是echo和print的区别了,自己总结了下:

echo()和print()区别小谈

同是字符串输出echo和echo、到底有啥区别尼?!!

PHP?言里说,其实哪个都不算很严密。他们都可以不用括弧()而正常工作。
目前只发现3点比较大的区别。

1. echo()可以用逗号「,」分割?数字符串, print()不可以

print   " Hello " , " World " ;  //  syntax error。
echo   " Hello " , " World " ;  //  syntax ok!!

※echo()用了括弧「()」以后,加逗号「,」区分?数字符串也不行!请注意。

2. print()返回?果、 echo()却不返回。

1 $output1   =   print   " Hello World " ;  //  这个有输出结果的
2 $output2   =   echo   " Hello World " ;  //  这个却没有哦

3.如果不需要返回结果操作的话、echo()要稍微快一些。

 

echo ()vs  print ()

Echoing  100000  of nothing
Exe Time is  0.034925937652588  secs .

Printing  100000  of nothing
Exe Time i s  0.037981986999512  secs .

这种差距你需要么请自己判断吧

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php开发总结Next article:PHP之字符集