Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
What is differece between echo and printf in php
What is differece between echo and printf in php
✍: santosh
PHP Echo Vs Print Diagram
";
echo "Hello World!
";
// The above outputs the text "Hello World!" on two separate lines.
// Notice they are identical in output!
print ("Hello World!
");
echo ("Hello World!
");
// The above are just the same, with parenthesis.
// Notice both can act like functions, but note they actually aren't.PHP Echo Vs Print Diagram
";
echo "Hello World!
";
// The above outputs the text "Hello World!" on two separate lines.
// Notice they are identical in output!
print ("Hello World!
");
echo ("Hello World!
");
// The above are just the same, with parenthesis.
// Notice both can act like functions, but note they actually aren't.
n all actuality, Echo and Print differ based on how they are structured. Print returns a value much like a normal function would. But despite common belief, Print is not a function, as we can see by the fact that it doesn’t require parenthesis to work (Not to be confused with Printf). Print and Echo are actually both called language constructs, although this isn’t to say that we can’t make Print act like a function.
Of course results depend on certain conditions, and the fact that we had to iterate the blocks of texts to an unimaginable amount of times to see a result shows that the difference really is marginal. It’s actually mentioned through a supporting page on the PHP.net homepage that developers should pick what suits them best- performance isn’t a real issue.
As a last note on speed, it’s recommended that developers add strings together via parameters- not through concatenation or multiple Echo calls. Instead of using new Echo commands to help organize code, separate them with commas (Make certain you aren’t using concatenation- this actually slows the process)! Calling the Echo or Print command multiple times will also degrade the performance of the script, although marginally, as seen below:
A Special Note On Concatenation Vs Parameters
";
// Concatenation slows down the process because PHP must add strings together
echo "Hello" , "
";
echo "World" , "
";
// Calling Echo multiple times still isn't as good as using Echo parameters solely
echo "Hello" , "World!" , "
";
// Correct! In a large loop, this could save a couple of seconds in the long run!
?>
So what do we use? Echo of course! But not because of speed, and certainly not because we have anything against pseudo-functions that are disguised as language constructs. So why do most PHP developers go for echo, when the benefits are very marginal?
Easy! It sounds cool! Not to mention the fact that the word Echo has one less letter in it that Print- and that’s saving our left pointing finger from having to press the “T” key each time we want to use the language construct in question.
It’s human nature to be lazy (Or have a certain appreciation for cool-sounding words), and that’s exactly the reason why you’ll see the majority of PHP developers use Echo over Print. The speed benefit is just icing on the cake.
2011-08-01, 4945👍, 0💬
Popular Posts:
Can you explain in brief how can we implement threading ? Private Sub Form1_Load(ByVal sender As Sys...
What Is Posting? Posting is an event that writes Inserts, Updates and Deletes in the forms to the da...
The object that contains all the properties and methods for every ASP.NET page, that is built is .. ...
How can we know the number of days between two given dates in PHP? Simple arithmetic: <?php $...
How To Create an Add-to-Netvibes Button on Your Website? - RSS FAQs - Adding Your Feeds to RSS News ...