在PHP中,结果输出一共有两种方式:echo和print,下面将对两种方式做一个比较。 echo与print的区别: |
echoprint连续输出字符串能连续输出多个字符串只能输出一个字符串返回值无返回1用法echo或echo()print或print()(1)echo能连续输出多个字符串,print只能输出一个字符串:
实例1:
<?PHP/*echo能连续输出多个字符串,print只能输出一个字符串*/echo "echo输出一个字符串:";echo "hello,world"; //echo输出一个字符串echo "<br/>"echo "echo输出多个字符串:"<span style="color: rgba(0,world","hello,PHP",python"; echo输出多个字符串;print "print输出一个字符串:"print "hello,1)">print输出一个字符串print "<br/>"start-【print连续输出多个字符串】-start*/
print "print输出多个字符串:"<span style="color: rgba(0,python"; print输出多个字符串,出错提示:Parse error: Syntax error,unexpected ',' in C:Users13842PHPstormProjectstestprint&echo.PHP on line 14/*end-【print连续输出多个字符串】-end*/;?>
屏蔽【print连续输出多个字符串】的代码,结果如下:

如果不屏蔽【print连续输出多个字符串】的代码,出现错误(语法错误):

(2)echo无返回值,print永远返回1
<?print返回1,echo无返回值*/$print_value=<span style="color: rgba(0,world<br/>"; 结果:hello,worldprint "返回值为$print_value"; 结果:返回值为1$echo_value=<span style="color: rgba(0,world<br/>"; 出现语法错误?>
(3)输出方式,带括号和不带括号没有什么区别,这里不做解释。
Technorati 标签: php,echo,print
(编辑:北几岛)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!