您好,欢迎访问一九零五行业门户网

php两种基本的输出方法是什么

php两种基本的输出方法是“echo”和“print”。echo用于输出一个或多个字符串,可接受多个参数且没有返回值,语法“echo($str)”;而print用于输出一个字符串,只能接受一个参数且有返回值,语法“print($str)”。
本教程操作环境:windows7系统、php7.1版、dell g3电脑
在 php 中,有两种基本的输出方法:echo 和 print。
echo 和 print 之间的差异
echo - 输出一个或多个字符串,可以接受多个参数并且没有返回值print - 只能输出一个字符串,只能接受一个参数并且有返回值,并始终返回 1提示:echo 比 print 稍快,因为它不返回任何值。
php echo 语句1.echo 是一个语言结构,有无括号均可使用:echo 或 echo();
2.显示字符串,下面的例子展示如何用 echo 命令来显示不同的字符串(同时请注意字符串中能包含 html 标记)
<?phpecho "<h2>php is fun!</h2>";echo(123);echo "<br>";echo("我爱php");echo "<br>";echo "hello world!<br>";echo "i'm about to learn php!<br>";echo "this", " string", " was", " made", " with multiple parameters.";?>
效果:
php is fun!123我爱phphello world!i'm about to learn php!this string was made with multiple parameters.
3.显示变量,下面的例子展示如何用 echo 命令来显示字符串和变量;
<?php$txt1="learn php";$txt2="w3school.com.cn";$cars=array("volvo","bmw","saab");echo $txt1;echo "<br>";echo "study php at $txt2 <br />";echo "my car is a {$cars[0]}";?>
效果:
learn phpstudy php at w3school.com.cn my car is a volvo

php print 语句1、print 也是语言结构,有无括号均可使用:print 或 print()。
2、显示字符串,下面的例子展示如何用 print 命令来显示不同的字符串(同时请注意字符串中能包含 html 标记):
<?phpprint "<h2>php is fun!</h2>";print "hello world!<br>";print "i'm about to learn php!";?>
效果:
php is fun!hello world!i'm about to learn php!
3.显示变量,下面的例子展示如何用 print 命令来显示字符串和变量:
<?php$txt1="learn php";$txt2="w3school.com.cn";$cars=array("volvo","bmw","saab");print $txt1;print "<br>";print "study php at $txt2 <br>";print "my car is a {$cars[0]}";?>
效果:
learn phpstudy php at w3school.com.cn my car is a volvo

推荐学习:《php视频教程》
以上就是php两种基本的输出方法是什么的详细内容。
其它类似信息

推荐信息