IT Community - Software Programming, Web Development and Technical Support

Difference between echo and print statement?

This is a discussion on Difference between echo and print statement? within the PHP Programming forums, part of the Web Development category; HI guys, Can any one explain what is the difference between echo and print statement? Thanks devarajan.V...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 07-25-2007, 08:38 AM
devarajan.v devarajan.v is offline
D-Web Master
 
Join Date: May 2007
Posts: 382
devarajan.v is on a distinguished road
Question Difference between echo and print statement?

HI guys,

Can any one explain what is the difference between echo and print statement?


Thanks
devarajan.V
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 07-26-2007, 09:37 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 881
kingmaker is on a distinguished road
Send a message via MSN to kingmaker
Thumbs up Re: Difference between echo and print statement?

Hi,

echo accepts multiple arguments, so a statement like echo "Hello ","world"; would give the same output as echo "Hello world";


echo doesn't return anything, but print does. It always returns an integer value of 1. That means a statement like $return = print "Hello World"; sets the value of $return to 1. Therefore, echo works maginally faster
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 07-30-2007, 03:26 AM
saravanan saravanan is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Posts: 180
saravanan is on a distinguished road
Default Re: Difference between echo and print statement?

hi
*Echo can take multiple expressions
*Print returns its success as a boolean. Echo on the other hand does not
return anything. This return call is the only difference I can think of off
hand. As for speed, returning a value does cost some cpu time but it is
usually a negligible amount. With that said, use whatever you feel like.
Personally, I use echo because it is faster, and I never check for any
return values on print statements. If you need to, say for important
information, then print should be used.
* Actually print has another use, because it returns true on success (and
why would it even return false in normal behaviour) so:

<?php
if(print('something'))
// makes sense, while

if(echo('something'))
// doesnt

?>
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Echo Row If problem jrdbrown1 PHP Programming 0 01-19-2009 08:38 AM
Google Print Ads dvduval Google 1 10-14-2007 03:46 PM
how to print iframe pdf document using file print menu using javascript kingmaker HTML, CSS and Javascript Coding Techniques 1 08-22-2007 04:32 AM
What is the difference between a statement and a block? sundarraja C and C++ Programming 4 08-10-2007 10:18 PM


All times are GMT -7. The time now is 11:40 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0