| echo vs print [message #2581] |
Thu, 26 February 2009 10:23  |
vicky7883 Messages: 2 Registered: February 2009 Location: The Netherlands |
Shiny and New |
|
|
Hi,
I am learning PHP5 now, and wondering what is the different between echo and print in PHP5. Could anyone help? Thanks.
Vicky
|
|
|
| Re: echo vs print [message #2583 is a reply to message #2581 ] |
Sat, 28 February 2009 16:08   |
|
Hiya!
Well, the difference are:
'Print' is a function. 'Echo' is not. For that reason Print receive just one parameter, which means it prints one thing. Echo can print a list of things separates by commas.
print ('something to print here');
echo 'something to print here', 'also another thing', 1;
I think also echo is more faster.
I hope it helps 
|
|
|
| Re: echo vs print [message #2584 is a reply to message #2581 ] |
Sun, 01 March 2009 10:32   |
|
Teknotica is right, confusingly though you can use echo with brackets just like a function! Personally I always use echo, sometimes with brackets
<?php echo("hello world"); ?>
and sometimes without
<?php echo "hello world"; ?>
I really think the two are interchangeable. Sometimes there are long mailing list arguments in differet places about one being faster than the other but realistically there aren't many applications where the speed of one over another will be the bottleneck!
Hope that helps,
Lorna
Lorna Mitchell (online at http://www.lornajane.net)
|
|
|
|
| Re: echo vs print [message #2616 is a reply to message #2583 ] |
Mon, 16 March 2009 07:21  |
Marion Messages: 114 Registered: October 2006 Location: Amsterdam, The Netherland... |
Member |

|
|
| Quote: | 'Print' is a function. 'Echo' is not. For that reason Print receive just one parameter, which means it prints one thing. Echo can print a list of things separates by commas.
|
Reading code a collegue of mine had written, I found 'print' expressions without parentheses, and they worked fine. That made me think and check the PHP manual.
It seems that 'print' is not a function after all, it's a language construct like 'echo'. Both 'print' and 'echo' work with and without parentheses, but if you want to 'echo' a list of things, you should not use parentheses.
Another difference that has not been mentioned yet: 'print' has a return value (always 1), 'echo' has not.
regards,
Marion
|
|
|