Home >Backend Development >PHP Tutorial >The difference between php echo and print statements
This article introduces to you the difference between the echo statement and the print statement in PHP5. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
The difference between echo and print:
echo - Can output one or multiple strings, has no return value
print - only allowed Output a string, The return value is always 1
Tips: echo outputs faster than print, echo has no return value, and print has a return value of 1.
Recommended: "PHP Tutorial"
echo is a language structure that uses You don't need to add parentheses, or you can add parentheses: echo or echo().
Display string
The following example demonstrates how to use the echo command to output a string (the string can contain HTML tags):
<?php echo "<h2>PHP 很有趣!</h2>"; echo "Hello world!<br>"; echo "我要学 PHP!<br>"; echo "这是一个", "字符串,", "使用了", "多个", "参数。"; ?>
How Output variables and strings
<?php $txt1="学习 PHP"; $txt2="liuhang"; $cars=array("Volvo","BMW","Toyota"); echo $txt1; echo "<br>"; echo " $txt2 爱学习 PHP "; echo "<br>"; echo "我车的品牌是 {$cars[0]}"; ?>
Except that only one string can be output at a time, it is the same as echo It's not that different.
<?php $txt1="学习 PHP"; $txt2="liuhang"; $cars=array("Volvo","BMW","Toyota"); print $txt1; print "<br>"; print " $txt2 爱学习 PHP "; print "<br>"; print "我车的品牌是 {$cars[0]}"; ?>
Recommended related articles:
Instance code of _get method and _set method access method in php
echo( in php )Usage of function (with code)
The above is the detailed content of The difference between php echo and print statements. For more information, please follow other related articles on the PHP Chinese website!