PHPecho & print

echo & print

echo and print are the two language constructs PHP gives you for sending text to the output buffer — the HTML response, a CLI terminal, wherever the script's output is headed. They look interchangeable in the simplest cases, which is exactly why people assume they're identical. They aren't quite: they differ in whether they return a value, whether they accept multiple arguments, and (in practice, negligibly) in raw speed. Knowing the difference means you'll pick the right one on purpose instead of by habit.

The basics

Simplest form of each

PHP
<?php

echo "Hello, world!";
print "Hello, world!";

// Both produce identical output for a single string.
Hello, world!Hello, world!
echo accepts multiple, comma-separated arguments

echo is a language construct, not a function, and one of its quirks is that it can take several expressions in one call, printing them back to back with no separator inserted.

Multiple arguments to echo

PHP
<?php

$name = 'Ada';
$role = 'engineer';

echo 'Name: ', $name, ', Role: ', $role, PHP_EOL;
Name: Ada, Role: engineer

print, by contrast, only ever accepts a single argument. Trying to pass it a comma-separated list is a syntax error — what looks like "multiple arguments" to print is actually just the comma operator, which PHP doesn't support the way some languages do.

This does NOT work

PHP
<?php

print 'Name: ', $name; // Parse error: syntax error, unexpected ','
print returns a value; echo does not

This is the most consequential difference. print is an expression that always evaluates to the integer 1, which means it can be used anywhere an expression is expected — inside a ternary, as an operand in a boolean expression, or chained with the and/or operators. echo, on the other hand, has no return value at all; it cannot be used inside another expression.

print's return value in a real expression

PHP
<?php

$loggedIn = true;

// print's return value (1) lets it live inside a boolean expression
$loggedIn and print('Welcome back!' . PHP_EOL);

// Capturing the return value directly (rarely useful, but it exists)
$result = print 'Saving...';
echo PHP_EOL . "print() returned: $result";
Welcome back!
Saving...
print() returned: 1

echo cannot be used as an expression

PHP
<?php

$x = echo 'test'; // Parse error: syntax error, unexpected token "echo"
The short echo tag

Inside HTML-heavy templates, wrapping every dynamic value in a full <?php echo ...; ?> block gets noisy fast. PHP provides a shorthand, <?= ?>, which is exact sugar for <?php echo ?> — including the fact that it can take echo's comma-separated argument list.

Short echo tags in a template

PHP
<?php $user = ['name' => 'Grace', 'unread' => 4]; ?>

<h2>Welcome, <?= $user['name'] ?></h2>
<p>You have <?= $user['unread'] ?> unread messages.</p>

<!-- Equivalent to writing <?php echo $user['name']; ?> etc. -->
Short echo tags are always available
Unlike the old `short_open_tag` setting that controlled the bare `<? ?>` tag (removed entirely in PHP 8), the short echo tag `<?= ?>` has been enabled unconditionally since PHP 5.4 and cannot be turned off. It's safe to use in any modern codebase and is the idiomatic choice inside `.php` view/template files.
Performance: does it actually matter?

Benchmarks consistently show echo as marginally faster than print — because print has to set up and return a value that echo never bothers computing. In practice this difference is a few nanoseconds per call and will never be the bottleneck in a real application; a single database query costs orders of magnitude more than the choice between these two constructs. Treat the performance angle as trivia, not as a reason to refactor.

When to reach for which

Situation

Prefer

Printing several values in one call

echo — accepts a comma list, no concatenation needed

Templating inside HTML markup

&lt;?= $value ?&gt; (the short echo tag)

Need the output call to act as an expression (ternaries, and/or chains)

print — it returns 1

General-purpose "just print this string"

echo — the idiomatic default

  • echo and print are language constructs, not functions — parentheses around their argument are optional and purely stylistic.

  • echo can take multiple comma-separated arguments; print takes exactly one.

  • print always evaluates to 1 and can be used inside expressions; echo has no value and cannot.

  • &lt;?= $expr ?&gt; is identical to &lt;?php echo $expr; ?&gt;.

  • The speed difference between them is real but practically irrelevant.

Tip
Default to `echo` for everyday output — it's the idiom most PHP developers expect, and its multi-argument form avoids unnecessary string concatenation with the `.` operator. Reach for `print` only when you specifically need its return value inside a larger expression; using it "just because" elsewhere in a codebase makes readers wonder if you meant something by it.