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...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| 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 |
| |||
| 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 ?> |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Google Print Ads | dvduval | 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 |