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 标签: ,,
  • 相关阅读:
    HTML5新增
    【目录】洛谷|CODEVS题解汇总
    【搜索】kkksc03考前临时抱佛脚
    【模拟】压缩技术
    【模拟】爱与愁的一千个伤心的理由
    【搜索】棋盘
    【模拟】图书管理员
    【递归】对称二叉树
    【题单】挖坑大行动
    【模拟】弹珠游戏
  • 原文地址:https://www.cnblogs.com/lijiaman/p/5793523.html
Copyright © 2011-2022 走看看