Echo Vs. Print In PHP - Difference And Comparison - Diffen

  • Health
  • Science
  • Tech
  • Home
  • Food
  • Business
  • Insurance
Diffen logo vs. echo vs. print in PHP Diffen › Technology › Computers › Software › Programming

echo() and print() are not functions but language constructs in PHP. They are both used to output strings and there are very minor differences between echo and print in PHP.

Comparison chart

echo versus print comparison chart
Edit this comparison chartechoprint
Parameters echo can take more than one parameter when used without parentheses. The syntax is echo expression [, expression[, expression] ... ]. Note that echo ($arg1,$arg2) is invalid. print only takes one parameter.
Return value echo does not return any value print always returns 1 (integer)
Syntax void echo ( string $arg1 [, string $... ] ) int print ( string $arg )
What is it? In PHP, echo is not a function but a language construct. In PHP, print is not a really function but a language construct. However, it behaves like a function in that it returns a value.

Speed of echo vs print in PHP

The speed of both echo and print statements in PHP is roughly the same. Using one over the other is not likely to yield any performance improvement in your application. Theoretically, echo is more efficient because it does not return any value.

Function vs Language Construct

Unlike most PHP string functions, echo and print aren't functions but language constructs. Therefore it is not required to use parentheses when using echo or print.

Parameters and syntax of print vs echo

When used with parentheses (like a function call), both print and echo take only 1 argument. For example,

echo("Don't panic!"); print("The answer is 42.");

However, when used without parentheses, echo can take several arguments. For example,

echo "Don't", " ", "panic", "!"; //This is valid. print "The ", "answer ", "is ", "42."; //This is invalid.

References

  • echo - PHP reference
  • print - PHP reference

About the Author

Nick Jasuja

Nick Jasuja has over 15 years of technology industry experience, including at Amazon in Seattle. He is an expert at building websites, developing software programs in PHP and JavaScript, maintaining MySQL and PostgreSQL databases, and running Linux servers for serving high-traffic websites. He has a bachelor's degree in Computer Science & Engineering.

  • self vs this in PHPself vs this in PHP
  • Java vs JavaScriptJava vs JavaScript
  • calloc() vs malloc()calloc() vs malloc()
  • Class vs ObjectClass vs Object
  • Constant vs LiteralConstant vs Literal
  • GET vs POSTGET vs POST
  • Share
  • Follow
  • Cite

Share this comparison via:

If you read this far, you should follow us:

"echo vs. print in PHP." Diffen.com. Diffen LLC, n.d. Web. 28 Dec 2024. < >

Comments: Echo (PHP) vs Print (PHP)

Anonymous comments (5)

January 8, 2014, 12:06pm

thanks. useful info..

— 203.✗.✗.69

August 3, 2013, 10:59am

Thank u boss......

— 118.✗.✗.218

October 25, 2011, 5:45am

Really very useful and fantastic way to illustrate ..!

— 180.✗.✗.222

April 16, 2014, 5:40pm

Thanku for find out diff b/w echo and print.....

— 115.✗.✗.157

January 8, 2014, 3:34pm

<?php echo "thanks"; ?>

— 106.✗.✗.69
Related Comparisons
  1. self vs this in PHP
  2. Java vs JavaScript
  3. calloc() vs malloc()
  4. Class vs Object
  5. Constant vs Literal
  6. GET vs POST
  7. Inner Join vs Outer Join
Contribute to Diffen

Edit or create new comparisons in your area of expertise.

Log in »
  • self vs this in PHPself vs this in PHP
  • Java vs JavaScriptJava vs JavaScript
  • calloc() vs malloc()calloc() vs malloc()
  • Class vs ObjectClass vs Object
  • Constant vs LiteralConstant vs Literal
  • GET vs POSTGET vs POST
Diffen logo About Diffen How to Cite Log in / Register Request a Comparison Submit Feedback

Stay connected

© All rights reserved.

Terms of use | Privacy policy

Từ khóa » E Echo Php