码迷,mamicode.com
首页 > Web开发 > 详细

php学习日志(3)-echo&print

时间:2016-08-21 21:11:40      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

      在php中,结果输出一共有两种方式:echo和print,下面将对两种方式做一个比较。

echo与print的区别:

  echo print
连续输出字符串 能连续输出多个字符串 只能输出一个字符串
返回值 返回1
用法 echo或echo() print或print()

(1)echo能连续输出多个字符串,print只能输出一个字符串:

实例1:

<?php
/*echo能连续输出多个字符串,print只能输出一个字符串*/
echo "echo输出一个字符串:";
echo "hello,world";  //echo输出一个字符串
echo "<br/>";
echo "echo输出多个字符串:";
echo "hello,world","hello,php","hello,python";   //echo输出多个字符串
echo "<br/>";

print "print输出一个字符串:";
print "hello,world";  //print输出一个字符串
print "<br/>";
/*start-【print连续输出多个字符串】-start*/
print "print输出多个字符串:";
print "hello,world","hello,php","hello,python";  //print输出多个字符串,出错提示:Parse error: syntax error, unexpected ‘,‘ in C:\Users\13842\PhpstormProjects\test\print&echo.php on line 14
/*end-【print连续输出多个字符串】-end*/print "<br/>";
?>

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

技术分享

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

技术分享

(2)echo无返回值,print永远返回1

<?php
/*print返回1,echo无返回值*/
$print_value=print "hello,world<br/>";  //结果:hello,world
print "返回值为$print_value";   //结果:返回值为1

$echo_value=echo "hello,world<br/>";   //出现语法错误
?>

(3)输出方式,带括号和不带括号没有什么区别,这里不做解释。

 

 

Technorati 标签: ,,

php学习日志(3)-echo&print

标签:

原文地址:http://www.cnblogs.com/lijiaman/p/5793523.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!