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

      在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连续输出多个字符串】的代码,结果如下:

cehoprint_1_thumb22

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

echoprint_thumb9

(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,echo,print
posted @ 2016-08-21 20:34  gegeman  阅读(759)  评论(0编辑  收藏  举报