Home > php教程 > php手册 > body text

PHP中echo(),print(),print

WBOY
Release: 2016-06-06 19:55:54
Original
1017 people have browsed it

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 echo ,print的区别在于echo 可以输出多个变量值,而print只有一个变量,做为一个字符串输出。 另一点区别在于echo 没有返回值,print有返回值1.print不能输出数组和对象。 print_r可以输出stirng、in

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  echo ,print的区别在于echo 可以输出多个变量值,而print只有一个变量,做为一个字符串输出。 另一点区别在于echo 没有返回值,print有返回值1.print不能输出数组和对象。

  print_r可以输出stirng、int、float、array、object等,输出array时会用结构表示,print_r输出成功时返回true;

  而且print_r可以通过print_r($str,true)来使print_r不输出而返回 print_r处理后的值。

  可以理解为:

  print 是打印字符串

  print_r 则是打印复合类型 如数组 对象等

  在PHP中的执行速率从快到慢为:echo(),   print(),   print_r()

  echo是PHP语句, print和print_r是函数,语句没有返回值,函数可以有返回值(即便没有用)

  print()    只能打印出简单类型变量的值(如int,string)

  print_r() 可以打印出复杂类型变量的值(如数组,对象)

  echo     输出一个或者多个字符串

  echo -- 输出一个或者多个字符串

  Descrīption

  void echo ( string arg1 [, string …] ) //返回值为空

  echo "你好"," 朋友";

  print --输出一个字符串

  Descrīption

  int print ( string arg )//返回值为整形

  print "你好朋友";

  可以进行下面操作

  $name=print "nihao /n";

  $str = 'test print value is $name .';

  eval_r("/$print=/"$str/";");

  echo $print;

  print_r -- 打印关于变量的易于理解的信息。

  bool print_r ( mixed expression [, bool return] ) //返回值是布尔型的,参数是mix类型的,可以是字符串,整形,数组,对象类print_r() 显示关于一个变量的易于理解的信息。如果给出的是 string、integer 或 float,将打印变量值本身。如果给出的是 array,将会按照一定格式显示键和元素。object 与数组类似。

[1] [2] 

PHP中echo(),print(),print

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!