Print or Echo Functions in PHP


 

Print or Echo Functions in PHP

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.

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.

Ads