Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 12th Jul 2010, 08:35 PM   #1
Warrior Member
 
Join Date: 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default
What the different between print and echo
Share on: 
fb share twitter share gplus share more share

Hi old warrior member, What is difference between print and echo
keyplay is offline  
Unread 12th Jul 2010, 10:38 PM   #2
VIP Warrior
War Room Member
 
ereadergold's Avatar
 
Join Date: 2008
Location: Montreal Canada
Posts: 2,390
Thanks: 1,017
Thanked 836 Times in 572 Posts
Blog Entries: 1
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

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
ereadergold is offline  
The Following User Says Thank You to ereadergold For This Useful Post:
Unread 13th Jul 2010, 12:42 AM   #3
Andy
War Room Member
 
Join Date: 2010
Posts: 49
Thanks: 31
Thanked 14 Times in 1 Post
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

Not much difference between print and echo.
The main differnce is that echo can take multiple expressions and its a bit faster than print


omonoiavas is offline  
Unread 13th Jul 2010, 05:27 AM   #4
Active Warrior
 
Join Date: 2010
Location: India
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

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

godwinsam is offline  
Unread 13th Jul 2010, 06:03 AM   #5
HyperActive Warrior
 
Join Date: 2008
Location: , , .
Posts: 182
Thanks: 0
Thanked 5 Times in 5 Posts
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

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.
jaratvit is offline  
Unread 3rd Aug 2010, 11:45 AM   #6
Warrior Member
 
Join Date: 2010
Location: City of Industry, California
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

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>
Luxmo is offline  
Unread 4th Aug 2010, 04:08 AM   #7
Warrior Member
 
Join Date: 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

echo can take multiple expressions + bit faster than print

ginny.smith73 is offline  
Unread 4th Sep 2010, 08:23 AM   #8
Warrior Member
 
Join Date: 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

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
rockmartinn24 is offline  
Unread 16th Feb 2011, 04:50 AM   #9
Active Warrior
 
Join Date: 2011
Posts: 35
Thanks: 0
Thanked 3 Times in 3 Posts
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

Yes not much difference between print and echo.
Only syntactically echo is different with print
abhishekcis is offline  
Unread 16th Feb 2011, 05:26 AM   #10
Active Warrior
 
Join Date: 2011
Posts: 31
Thanks: 0
Thanked 1 Time in 1 Post
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

Print : Prints the Line with formatted output
Echo : Just print and goes to next line
tirupati is offline  
Unread 21st Mar 2011, 06:22 PM   #11
Active Warrior
 
Join Date: 2011
Posts: 25
Thanks: 1
Thanked 1 Time in 1 Post
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

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.

sixpack01 is offline  
Unread 21st Mar 2011, 07:04 PM   #12
HyperActive Warrior
 
Join Date: 2010
Posts: 347
Thanks: 24
Thanked 20 Times in 20 Posts
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

Basic difference is that echo is not a function like print(). As such echo runs faster than print().

gtk29 is offline  
Unread 29th Mar 2011, 12:40 PM   #13
Warrior Member
 
Join Date: 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

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.

joshepmacarona is offline  
Unread 29th Mar 2011, 05:50 PM   #14
Active Warrior
War Room Member
 
Join Date: 2009
Location: Maidens, VA
Posts: 42
Thanks: 21
Thanked 12 Times in 9 Posts
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

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.

esoomllub is offline  
Unread 31st Mar 2011, 03:47 AM   #15
Warrior Member
 
Join Date: 2011
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

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.
yourmobisite is offline  
Unread 1st Apr 2011, 02:06 AM   #16
Graphic Artist & Designer
War Room Member
 
Steve Wells's Avatar
 
Join Date: 2009
Location: Kansas City, MO
Posts: 2,063
Thanks: 123
Thanked 447 Times in 249 Posts
Blog Entries: 3
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share


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!
Steve Wells is offline  
Unread 1st Apr 2011, 05:34 AM   #17
Night Angel
 
hhunt's Avatar
 
Join Date: 2009
Location: Underground
Posts: 158
Thanks: 2
Thanked 14 Times in 14 Posts
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

Originally Posted by Steve Wells View Post


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

You may have misunderstood the question - the print and echo in this context relate to programming languages; rather than the real world interpretation of it.

hhunt is offline  
Unread 1st Apr 2011, 06:56 AM   #18
Advanced Warrior
 
hireava's Avatar
 
Join Date: 2010
Posts: 612
Thanks: 0
Thanked 32 Times in 32 Posts
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

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.

hireava is offline  
Unread 6th Apr 2011, 12:35 AM   #19
Active Warrior
 
Join Date: 2011
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

Lagest difference is: Print is suitable for conditional construct - but echo - not
alexacc is offline  
Unread 11th Apr 2011, 02:23 PM   #20
Graphic Artist & Designer
War Room Member
 
Steve Wells's Avatar
 
Join Date: 2009
Location: Kansas City, MO
Posts: 2,063
Thanks: 123
Thanked 447 Times in 249 Posts
Blog Entries: 3
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

Originally Posted by hhunt View Post

You may have misunderstood the question - the print and echo in this context relate to programming languages; rather than the real world interpretation of it.
Naay, just having fun....

Need Custom Graphics Work? - Message Me For A Design Quote!
Steve Wells is offline  
Unread 12th Apr 2011, 07:15 AM   #21
Warrior Member
 
Join Date: 2011
Posts: 5
Thanks: 0
Thanked 1 Time in 1 Post
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

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.

kitchensimply is offline  
Unread 14th Apr 2011, 04:31 AM   #22
Warrior Member
 
Join Date: 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

As for echo statement.it doesn't return value of , the print which always return one and 0.


Janessabourne is offline  
Unread 14th Apr 2011, 06:11 AM   #23
PHP Developer
War Room Member
 
Join Date: 2010
Location: World
Posts: 79
Thanks: 14
Thanked 6 Times in 6 Posts
Blog Entries: 2
Lightbulb
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

For example, you can use this with print.
PHP Code:
mysql_query() or print(mysql_error()); 
You can't do it with echo
PHP Code:
mysql_query() or echo(mysql_error());// will fail 

Hello world
xrvel is offline  
Unread 14th Apr 2011, 07:54 AM   #24
Warrior Member
 
Join Date: 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

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.

ronspals is offline  
Unread 18th Apr 2011, 02:25 AM   #25
Wordpress Master
 
oknoorap's Avatar
 
Join Date: 2010
Location: Asia
Posts: 70
Thanks: 1
Thanked 4 Times in 4 Posts
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

echo vs. print

Benchmarks :

Code:
echo ''
Total time: 159 µs

Code:
print ''
Total time: 138 µs

Code:
echo 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa'
Total time: 194 µs

Code:
print 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa'
Total time: 178 µs

Code:
echo 'aaaaaaa'.'aaaaaaa'.'aaaaaaa'.'aaaaaaa'
Total time: 217 µs

Code:
echo 'aaaaaaa','aaaaaaa','aaaaaaa','aaaaaaa'
Total time: 521 µs

Code:
print 'aaaaaaa'.'aaaaaaa'.'aaaaaaa'.'aaaaaaa'
Total time: 245 µs

Code:
$ var = 'aaaaaaa';
echo 'aaaaaaa'.$ var.'aaaaaaa'.
Total time: 622 µs

Code:
$ var = 'aaaaaaa';
echo 'aaaaaaa',$ var,'aaaaaaa',
Total time: 794 µs

Code:
$ var = 'aaaaaaa';
print 'aaaaaaa'.$ var.'aaaaaaa'.
Total time: 890 µs

Code:
$ var = 'aaaaaaa';
echo $ var.$ var.$ var.$ var
Total time: 937 µs

Code:
$ var = 'aaaaaaa';
echo $ var,$ var,$ var,$ var
Total time: 894 µs

Code:
$ var = 'aaaaaaa';
print $ var,$ var,$ var,$ var
Total time: 1009 µs

remove space between dollar and var.

Just Web Developer.
oknoorap is offline  
Unread 29th Apr 2011, 11:27 AM   #26
Warrior Member
 
Join Date: 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

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.
dealsbells is offline  
Unread 29th Apr 2011, 01:51 PM   #27
Warrior Member
 
CodeMyConcept's Avatar
 
Join Date: 2011
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

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.
CodeMyConcept is offline  
Unread 1st May 2011, 01:32 AM   #28
UMS
Peter Sundstrom
War Room Member
 
UMS's Avatar
 
Join Date: 2010
Location: New Zealand
Posts: 3,277
Thanks: 291
Thanked 888 Times in 671 Posts
Blog Entries: 2
Default
Re: What the different between print and echo
Share on: 
fb share twitter share gplus share more share

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.

UMS is offline  
Closed Thread


Bookmarks

Tags
echo, print


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 02:51 AM.