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.

echoprint
Returns nothingAlways returns 1
Can take many values separated by commaTakes only one value
Can not be used inside an expressionCan 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
PHP Introduction
PHP Terminology
PHP Installation
PHP Syntax
PHP Comments
PHP exit() Function
Exercises & Assignments
Write a program to print “Hello World” using echo
Simple Tips for PHP Beginners
Experiment with Basic PHP Syntax Errors
Using phpinfo() – Display PHP Configuration & Modules
Interview Questions & Answers
What is PHP?
Who is the father of PHP?
What is the correct & common way to start and finish a PHP block of code?
What is Open Source Software?
What is the default extension of the PHP file?
What is the latest version of PHP?
What is the full form of PHP?