Free tutorials in Hindi & English Daily computer, mobile and IT guides Beginner friendly learning
Blog · PHP · 04 Jul 2026 · Hindi + English

Difference Between echo and print in PHP

echo is a construct that outputs multiple values with no return; print takes one value and returns 1. Speed truth, comma trick and when it actually matters.

The honest one-line answer

Both send output to the browser, and in daily work they feel identical. The real differences: echo is a language construct that accepts multiple values and returns nothing; print accepts exactly one value and returns 1 (so it can live inside an expression). That return value is the whole story.
<?php
echo "Hello World";      // works
print "Hello World";     // works - same visible result
?>
Hello WorldHello World

Difference 1: multiple values (the comma trick)

<?php
$name = "Aman"; $marks = 92;

echo "Student: ", $name, " | Marks: ", $marks;   // commas - echo only!
// print "a", "b";        // FATAL ERROR - print takes ONE argument
print "Student: " . $name;                        // print must concatenate
?>
Student: Aman | Marks: 92Student: Aman

Bonus: the comma version of echo is actually a hair faster than dot-concatenation, because PHP outputs the pieces directly instead of building one big string first. On shared hosting with heavy pages, echo with commas is the clean habit.

Difference 2: print returns 1

<?php
$r = print "Hello";      // valid! $r becomes 1
echo $r;

// $x = echo "Hi";       // PARSE ERROR - echo returns nothing,
                          // cannot be used inside an expression

// where print's return sneaks into real code (rare but legal):
$loggedIn = false;
$loggedIn or print "Please login first";
?>
Hello1Please login first

Because print returns a value, it behaves like a function inside expressions. echo cannot do this — it is pure output, no value. This single point is what the interviewer is checking.

Comparison table

Pointechoprint
TypeLanguage constructLanguage construct
ArgumentsMultiple: echo $a, $b, $c;Exactly one
Return valueNoneAlways 1
Usable in expressions❌ No✅ Yes
SpeedMarginally fasterMarginally slower (returns 1)
ParenthesesOptional: echo("hi") worksOptional: print("hi") works
Common myth to avoid in interviews: "echo is a construct, print is a function" — wrong. BOTH are language constructs (that is why both work without parentheses). print merely behaves function-like because it returns 1. Saying it correctly earns instant credibility.

What real code uses

Practically all professional PHP — WordPress, Laravel templates, your own projects — uses echo, plus its shortcut in HTML templates:

<p>Welcome, <?= $name ?></p>
<!-- <?= ... ?> is short for <?php echo ... ?> -->

Interview line: "Both are constructs; echo takes multiple arguments and returns nothing, print takes one and returns 1, so only print can sit inside an expression. In practice, echo everywhere."

ईमानदार one-line answer

दोनों browser को output भेजते हैं, और रोज़ के काम में एक जैसे लगते हैं. असली अंतर: echo एक language construct है जो कई values लेता है और कुछ return नहीं करता; print exactly एक value लेता है और 1 return करता है (इसलिए expression के अंदर बैठ सकता है). वही return value पूरी कहानी है.
<?php
echo "Hello World";      // चलता है
print "Hello World";     // चलता है - same दिखने वाला result
?>
Hello WorldHello World

अंतर 1: multiple values (comma trick)

<?php
$name = "Aman"; $marks = 92;

echo "Student: ", $name, " | Marks: ", $marks;   // commas - सिर्फ echo!
// print "a", "b";        // FATAL ERROR - print EK argument लेता है
print "Student: " . $name;                        // print को concatenate करना पड़ता है
?>
Student: Aman | Marks: 92Student: Aman

Bonus: echo का comma version dot-concatenation से हल्का-सा तेज़ है, क्योंकि PHP एक बड़ी string बनाने की बजाय टुकड़े सीधे output करता है. Shared hosting पर heavy pages में commas वाला echo अच्छी आदत है.

अंतर 2: print 1 return करता है

<?php
$r = print "Hello";      // valid! $r बन गया 1
echo $r;

// $x = echo "Hi";       // PARSE ERROR - echo कुछ return नहीं करता,
                          // expression के अंदर use नहीं हो सकता

// print का return असली code में कहां घुसता है (rare पर legal):
$loggedIn = false;
$loggedIn or print "Please login first";
?>
Hello1Please login first

Print value return करता है, इसलिए expressions के अंदर function जैसा behave करता है. echo यह नहीं कर सकता — वह pure output है, कोई value नहीं. Interviewer यही एक point check कर रहा होता है.

Comparison table

Pointechoprint
TypeLanguage constructLanguage construct
Argumentsकई: echo $a, $b, $c;Exactly एक
Return valueकुछ नहींहमेशा 1
Expression में use❌ नहीं✅ हां
Speedज़रा-सा तेज़ज़रा-सा धीमा (1 return करता है)
ParenthesesOptional: echo("hi") चलता हैOptional: print("hi") चलता है
Interview में इस myth से बचें: "echo construct है, print function है" — गलत. DONO language constructs हैं (इसीलिए दोनों बिना parentheses चलते हैं). print बस 1 return करने की वजह से function-जैसा behave करता है. सही बोलेंगे तो तुरंत credibility बनेगी.

असली code क्या use करता है

लगभग सारा professional PHP — WordPress, Laravel templates, आपके अपने projects — echo use करता है, plus HTML templates में उसका shortcut:

<p>Welcome, <?= $name ?></p>
<!-- <?= ... ?> मतलब <?php echo ... ?> -->

Interview line: "दोनों constructs हैं; echo कई arguments लेता है और कुछ return नहीं करता, print एक लेता है और 1 return करता है, इसलिए सिर्फ print expression में बैठ सकता है. Practice में हर जगह echo."

Frequently Asked Questions

What is the difference between echo and print in PHP?

echo outputs multiple comma-separated values and returns nothing; print outputs exactly one value and returns 1, so only print can be used inside an expression. Both are language constructs.

Is print a function in PHP?

No — print is a language construct like echo; it only behaves function-like because it returns 1, and parentheses around its argument are optional.

Which is faster, echo or print?

echo is marginally faster since it returns nothing, and echo with commas avoids building a concatenated string — but the difference is negligible in real applications.