Share on Google+Share on Google+

Print or Echo Functions in PHP

Advertisement
Although the use of both Print and Echo function are same, but it has been seen that people mostly uses echo command more then the print command.

Print or Echo Function in PHP

Although the use of both Print and Echo are same, but it has been seen that people uses echo command more then the print command. But that’s completely a personal preference, you can use whatever you wanted to use.

 We don’t see much difference between these two commands as both prints value on the web pages. But on comparing we can say that echo is bit faster then print command, as it does not return any value. On the other side Print command returns true or false (Boolean) value that takes some time to process.

Lets take an example of print and echo command:

<?php

print "Hello <br />";
echo " World!";
?>
Output:
Hello
World!

As you can see in the output both print & echo commands are printing the assigned value on the browser without any error. That means both the commands are correct and capable enough to print the value. So, it depends on you which command you wanted to use.

Advertisements

Advertisement

Posted on: October 27, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.