Home > Backend Development > PHP Tutorial > The difference between php echo and print statements

The difference between php echo and print statements

不言
Release: 2023-04-03 14:48:01
Original
2759 people have browsed it

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 php echo and print statements

PHP echo and print statements

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"

PHP echo statement

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 "这是一个", "字符串,", "使用了", "多个", "参数。";
?>
Copy after login

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]}";
?>
Copy after login

print statement

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]}";
?>
Copy after login

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!

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template