php学习日志 - echo&print

前端之家收集整理的这篇文章主要介绍了php学习日志 - echo&print前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

      在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:\Users\13842\PHPstormProjects\test\print&echo.PHP on line 14/*end-【print连续输出多个字符串】-end*/;?>

屏蔽【print连续输出多个字符串】的代码,结果如下:

cehoprint_1_thumb22

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

echoprint_thumb9

(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 标签: ,,

原文链接:https://www.f2er.com/php/997665.html

猜你在找的PHP相关文章