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 (permalink)  
Old 07-25-2007, 09: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
Sponsored Links
  #2 (permalink)  
Old 07-26-2007, 10:37 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo 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 (permalink)  
Old 07-30-2007, 04:26 AM
saravanan saravanan is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Posts: 181
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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Google Print Ads dvduval Google 1 10-14-2007 04:46 PM
How can I print my output? S.Vinothkumar C and C++ Programming 2 10-13-2007 12:46 AM
how to print iframe pdf document using file print menu using javascript kingmaker HTML, CSS and Javascript Coding Techniques 1 08-22-2007 05:32 AM
What is the difference between a statement and a block? sundarraja C and C++ Programming 4 08-10-2007 11:18 PM
How you print the array using Perl? raj Perl 1 07-25-2007 01:02 AM


All times are GMT -7. The time now is 02:03 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0