Echo Vs. Print In PHP - Difference And Comparison - Diffen
Có thể bạn quan tâm
- Health
- Science
- Tech
- Home
- Food
- Business
- Insurance
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 | ||
---|---|---|
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 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.
Related Comparisons
- self vs this in PHP
- Java vs JavaScript
- calloc() vs malloc()
- Class vs Object
- Constant vs Literal
- GET 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
Related ComparisonsJanuary 8, 2014, 3:34pm
<?php echo "thanks"; ?>
— 106.✗.✗.69
- self vs this in PHP
- Java vs JavaScript
- calloc() vs malloc()
- Class vs Object
- Constant vs Literal
- GET vs POST
- Inner Join vs Outer Join
Edit or create new comparisons in your area of expertise.
Log in »- self vs this in PHP
- Java vs JavaScript
- calloc() vs malloc()
- Class vs Object
- Constant vs Literal
- GET vs POST
Stay connected
© All rights reserved.
Terms of use | Privacy policyTừ khóa » E Echo Php
-
PHP Echo And Print Statements - W3Schools
-
PHP Echo() Function - W3Schools
-
Echo - Manual - PHP
-
Echo -e Content Of File Fetched Using Foreach - Stack Overflow
-
PHP Echo And Print - Pi My Life Up
-
How To Use Echo To Print Data In PHP
-
Qual é A Diferença Entre Echo, Print E Print_r Em PHP? - Acervo Lima
-
PHP Echo And Print - GeeksforGeeks
-
Curso De PHP/Comandos/Echo - Wikilivros
-
Diferença Entre Echo E Print Em PHP - Natapa
-
Display All PHP Errors: Basic & Advanced Usage
-
WuT x 2: TCP Echo Server With PHP
-
How To Check PHP Version {2 Methods Explained} - PhoenixNAP
-
Home - Twig - The Flexible, Fast, And Secure PHP Template Engine