zoukankan      html  css  js  c++  java
  • 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:Users13842PhpstormProjects	estprint&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 标签: ,,
  • 相关阅读:
    haproxy2.0入门部署教程【转】
    备份复制特定以开头的目录下的文件
    Python对比俩个文件内容
    常用prometheus告警规则模板(三)【转】
    prometheus告警技术初探(一)【转】
    prometheus告警规则设置(二)【转】
    SQL Server AlwaysOn搭建【转】
    linux使用bash-completion补全【原创】
    定时清理elasticsearch【原创】
    windows系统垃圾清理脚本【转】
  • 原文地址:https://www.cnblogs.com/lijiaman/p/5793523.html
Copyright © 2011-2022 走看看