There are two basic output modes in PHP: Echo and print. In this article, we'll discuss the use of both statements in detail, and demonstrate in the example how Echo and print are used.
PHP Echo and Print statements
Echo and Print differences:
echo-can output one or more strings
Print-allows only one string to be output, with a total return value of 1
Tip: The echo output is faster than print, ECHO has no return value, and print has a return value of 1.
PHP Echo Statement
Echo is a language structure that can be used without parentheses or parentheses: Echo or Echo ().
Display string
The following example shows how to use the echo command to output a string (the string can contain HTML tags):
Instance
<?phpecho "
Try it»
Show variables
The following example shows how to use the echo command to output variables and strings:
Instance
<?php$txt1= "Learning php", $txt 2= "runoob.com", $cars =array ("Volvo", "BMW", "Toyota"); echo $txt 1;echo "<br>", echo "in $txt 2 to learn PHP"; echo "<br>" echo "The brand of my car is {$cars [0]}";? >
PHP Print Statement
Print is also a language structure, you can use parentheses, or you can use no parentheses: Print or print ().
Display string
The following example shows how to use the Print command to output a string (the string can contain HTML tags):
Instance
<?phpprint "
Show variables
The following example shows how to use the Print command to output variables and strings:
Instance
<?php$txt1= "Learning php", $txt 2= "runoob.com", $cars =array ("Volvo", "BMW", "Toyota"); Print $txt 1;print "<br>";p rint "in $txt 2 to learn PHP";p rint "<br>";p rint "the brand of my car is {$cars [0]}";? >
This article on the PHP 5 echo and Print statements related knowledge and use to make some explanations, more learning materials to clear concern about the PHP Chinese network can be viewed.