PHP: Echo vs Print

Sean Wragg
Sep 2, 2008 · 2 min read

The following is derived from my post on the (now defunct) forums.

This is a hot topic for those just getting into php. Understanding the difference between print() and echo can be challenging for those unfamiliar with the language.

In my opinion, it really depends what your trying to accomplish that will determine which you should use. Some things to consider:

  1. echo is marginally faster than print()
  2. print() is a function, which can be used in more complex operations.
  3. echo can handle multiple parameters.

echo is faster

As stated, echo is marginally faster than print(). If you’re wondering how much faster, take a look at this.

I’ve created two php snippets: echo.php and print.php

Then I made a snippet to time them both: test.php.

We execute our test.php and see our results.

So ultimately, we confirm that echo is only slightly faster than print().

print() is a function

However, this doesn’t necessarily mean that echo is better than print(), because print() can do something that echo can’t - it can be placed in more complex operations since it's a function.

Within the above, if the variable $i is set this snippet will print true. Since print() is a function, it’s able to be used within this operation, where echo can not. In fact if you were to attempt to use echo within this statement, php will error in:

echo accepts multiple parameters

Finally, echo can handle multiple parameters but, I think that pretty much speaks for itself. Give the following a try:

So, as stated, it really just depends on what your trying to accomplish. Others may have a different opinion but this is mine and I’m entitled to it :P

Originally published at on September 2, 2008.

Code, Comics, and Fhqwhgads!

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store