| | #1 |
| Warrior Member Join Date: 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
Hi old warrior member, What is difference between print and echo
|
| |
| | #2 |
| VIP Warrior War Room Member Join Date: 2008 Location: Montreal Canada
Posts: 2,390
Thanks: 1,017
Thanked 836 Times in 572 Posts
Blog Entries: 1 |
Who are you calling "old"???? I assume you are speaking about PHP here, as many other languages use similar statements. Technically echo is a bit faster than print, although we are probably talking nanoseconds here. Print also has a return value (i.e true or false), where as echo doesn't. However echo can accept multiple statements but print can't (i.e echo "The first", "the second";). For all practical purposes use the one that makes you happy! I guess echo has one less character to type! Bill |
| |
| The Following User Says Thank You to ereadergold For This Useful Post: |
| | #3 |
| Andy War Room Member Join Date: 2010
Posts: 49
Thanks: 31
Thanked 14 Times in 1 Post
|
Not much difference between print and echo. The main differnce is that echo can take multiple expressions and its a bit faster than print |
| | |
| |
| | #4 |
| Active Warrior Join Date: 2010 Location: India
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
| print does the same thing as echo except echo is a language construct and not a real function so it's syntax is different. echo is a statement while print is a function we can't print whole array by using echo or print. For this we have to use the print_r function |
| | |
| |
| | #5 |
| HyperActive Warrior Join Date: 2008 Location: , , .
Posts: 182
Thanks: 0
Thanked 5 Times in 5 Posts
|
A lot of people seem to prefer echo because it runs a little faster (very likely an insignificant amount of time will be gained). There are a few situations in more complicated code where print is preferred because it can return a true/false where echo does not. Very few people care about these technical differences and use them interchangeably. |
| |
| | #6 |
| Warrior Member Join Date: 2010 Location: City of Industry, California
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
Personally, I use echo for generic printing to the document..specially when there is a lot of printing to be done. I only use the print function when there is further formatting or processing needed...like making sure something was printed using the bool return from the print function or formatting strings (like currency formats). Echo is faster than print and there is a noticeable speed difference when printing large strings. To sum it up: Use echo when printing anything. Only use print when you need to print something in a special way or for bool testing. <My two pennies> |
| |
| | #7 |
| Warrior Member Join Date: 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
echo can take multiple expressions + bit faster than print
|
| | |
| |
| | #8 |
| Warrior Member Join Date: 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
The different between print and echo : - Echo works faster than print() - Echo and print are language construct - Echo is not suitable for conditional construct - Print is suitable for conditional construct - Print process is slower than echo - Print returns an integer values - Echo does not returns any values |
| |
| | #9 |
| Active Warrior Join Date: 2011
Posts: 35
Thanks: 0
Thanked 3 Times in 3 Posts
|
Yes not much difference between print and echo. Only syntactically echo is different with print |
| |
| | #10 |
| Active Warrior Join Date: 2011
Posts: 31
Thanks: 0
Thanked 1 Time in 1 Post
|
Print : Prints the Line with formatted output Echo : Just print and goes to next line |
| |
| | #11 |
| Active Warrior Join Date: 2011
Posts: 25
Thanks: 1
Thanked 1 Time in 1 Post
|
The difference between print() & echo()? 1. Echo() can take multiple expression eg: Echo 'sundar','MCA'; // sundarMCA 2. Print() cannot take multiple expression eg print 'sundar','MCA'; // Parse Error 3. Echo() doesn`t return any values. 4.print() return values. |
| | |
| |
| | #12 |
| HyperActive Warrior Join Date: 2010
Posts: 347
Thanks: 24
Thanked 20 Times in 20 Posts
|
Basic difference is that echo is not a function like print(). As such echo runs faster than print().
|
| | |
| |
| | #13 |
| Warrior Member Join Date: 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
Prints the Line with formatted output. Echo is just print and goes to next line. Echo is not best for conditionally construct. Print is best for conditionally construct.
|
| | |
| |
| | #14 |
| Active Warrior War Room Member Join Date: 2009 Location: Maidens, VA
Posts: 42
Thanks: 21
Thanked 12 Times in 9 Posts
|
The funny thing to me is that even though I know they are pretty close to the same, I find myself constantly changing prints to echos when I take over code from someone else. I realize that it is a waste of time, but still can not find the willpower to stop myself. Argh.
|
| | |
| |
| | #15 |
| Warrior Member Join Date: 2011
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
Some people seem to prefer echo because it runs a little faster.There are a few situations in more complicated code where print is preferred because it can return a true/false where echo does not.
|
| |
| | #16 |
| Graphic Artist & Designer War Room Member Join Date: 2009 Location: Kansas City, MO
Posts: 2,063
Thanks: 123
Thanked 447 Times in 249 Posts
Blog Entries: 3 | Print: a process for reproducing text and image, typically with ink on paper using a printing press. It is often carried out as a large-scale industrial process, and is an essential part of publishing and transaction printing Echo: Repetition of a sound by reflection of sound waves from a surface |
| Need Custom Graphics Work? - Message Me For A Design Quote! | |
| |
| | #17 | |
| Night Angel Join Date: 2009 Location: Underground
Posts: 158
Thanks: 2
Thanked 14 Times in 14 Posts
|
| |
| | ||
| |
| | #18 |
| Advanced Warrior Join Date: 2010
Posts: 612
Thanks: 0
Thanked 32 Times in 32 Posts
|
Main difference between echo() and print() is that echo is just an statement not a function and doesn't return's value or it just prints a value whereas print() is an function which prints a value and also it returns value.
|
| | |
| |
| | #19 |
| Active Warrior Join Date: 2011
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
|
Lagest difference is: Print is suitable for conditional construct - but echo - not
|
| |
| | #21 |
| Warrior Member Join Date: 2011
Posts: 5
Thanks: 0
Thanked 1 Time in 1 Post
|
echo has the slight performance advantage because it doesn't have a return value. They both have the same functions but have different procedures that result to the same output.
|
| | |
| |
| | #22 |
| Warrior Member Join Date: 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
As for echo statement.it doesn't return value of , the print which always return one and 0. |
| | |
| |
| | #23 |
| PHP Developer War Room Member |
For example, you can use this with print. PHP Code: PHP Code: |
|
Hello world
| |
| |
| | #24 |
| Warrior Member Join Date: 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
Echo can take multiple parameters to echo.This is not true with print. The "echo" and "print" tests can be tailored depending on what you are actually using it for. In general echo is faster, although there's cases where print can be faster.
|
| | |
| |
| | #25 |
| Wordpress Master Join Date: 2010 Location: Asia
Posts: 70
Thanks: 1
Thanked 4 Times in 4 Posts
|
echo vs. print Benchmarks : Code: echo '' Code: print '' Code: echo 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa' Code: print 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa' Code: echo 'aaaaaaa'.'aaaaaaa'.'aaaaaaa'.'aaaaaaa' Code: echo 'aaaaaaa','aaaaaaa','aaaaaaa','aaaaaaa' Code: print 'aaaaaaa'.'aaaaaaa'.'aaaaaaa'.'aaaaaaa' Code: $ var = 'aaaaaaa'; echo 'aaaaaaa'.$ var.'aaaaaaa'. Code: $ var = 'aaaaaaa'; echo 'aaaaaaa',$ var,'aaaaaaa', Code: $ var = 'aaaaaaa'; print 'aaaaaaa'.$ var.'aaaaaaa'. Code: $ var = 'aaaaaaa'; echo $ var.$ var.$ var.$ var Code: $ var = 'aaaaaaa'; echo $ var,$ var,$ var,$ var Code: $ var = 'aaaaaaa'; print $ var,$ var,$ var,$ var remove space between dollar and var. |
|
Just Web Developer.
| |
| |
| | #26 |
| Warrior Member Join Date: 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
Echo is a statement print is a function.echo print the multiple function but print function print statement.The only difference between print & echo is that both of them displays leads to different format.
|
| |
| | #27 |
| Warrior Member Join Date: 2011
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
|
Both do the same job, but there is a slight difference between print and echo so it usually comes down to a matter of personal preference.
|
|
Our service is targeted to agencies and freelancers, the job done by us is 100% confidential. In addition, we are offering a 100% money back guarantee.
| |
| |
| | #28 |
| Peter Sundstrom War Room Member Join Date: 2010 Location: New Zealand
Posts: 3,277
Thanks: 291
Thanked 888 Times in 671 Posts
Blog Entries: 2 |
Given the programming language wasn't specified, I'll assume bash as the language. In which case, echo is a builtin bash function, whereas print is an external command and therefore requires the overhead (albeit small) to fork a new process. |
| | |
| |
|
| Bookmarks |
| Tags |
| echo, print |
| |