What is the difference between echo and print in PHP?
echo and print both are used to show output in PHP. They are language constructs, so brackets are optional. The main differences are in the table below.
| echo | |
|---|---|
| Returns nothing | Always returns 1 |
| Can take many values separated by comma | Takes only one value |
| Can not be used inside an expression | Can be used inside an expression |
<?php
echo "Hello", " ", "World", "<br>"; // many parameters
$r = print "Hi"; // print returns 1
echo "<br>" . $r;
?>
Output:
Tutorials Class - Output Window
Hello World
Hi
1
People say echo is a little faster than print, but the difference is so small that you will never notice it. Use echo in most cases.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |