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

php echo和print

时间:2016-05-17 11:15:29      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

在 PHP 中,有两种基本的输出方法:echo 和 print

PHP echo 和 print 语句

echo 和 print 之间的差异:

  • echo - 能够输出一个以上的字符串
  • print - 只能输出一个字符串,并始终返回 1

提示:echo 比 print 稍快,因为它不返回任何值。

PHP echo 语句

echo 是一个语言结构,有无括号均可使用:echo 或 echo()。

显示字符串

<?php
echo "<h2>PHP is fun!</h2>";
echo "Hello world!<br>";
echo "I‘m about to learn PHP!<br>";
echo "This", " string", " was", " made", " with multiple parameters.";
?>

显示变量

<?php
$txt1="Learn PHP";
$txt2="W3School.com.cn";
$cars=array("Volvo","BMW","SAAB");

echo $txt1;
echo "<br>";
echo "Study PHP at $txt2";
echo "My car is a {$cars[0]}";
?>

PHP print 语句

print 也是语言结构,有无括号均可使用:print 或 print()。

显示字符串

<?php
print "<h2>PHP is fun!</h2>";
print "Hello world!<br>";
print "I‘m about to learn PHP!";
?>

显示变量

<?php
$txt1="Learn PHP";
$txt2="W3School.com.cn";
$cars=array("Volvo","BMW","SAAB");

print $txt1;
print "<br>";
print "Study PHP at $txt2";
print "My car is a {$cars[0]}";
?>

php echo和print

标签:

原文地址:http://www.cnblogs.com/rae-sai/p/5500519.html

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