Multi
Multi
Vector Series - Echo vs Print
Topic Started: Thursday, 24. November 2011, 11:40 (367 Views)
Andrew
Member Avatar
ぼくたちがすべてはばか。
Quote:
 
Echo vs Print
Time: 5 Minutes
Difficulty: Easy



Since Oracle asked for it, here it is. What's the difference between PHP's echo and print? They both look similar in both syntax and function. Let's look at an example:
Code: PHP
 
echo 'Foo\'s';
print 'Foo\'s';
Both of these statements will output "Foo's" resulting in "Foo'sFoo's". Both also support escape sequences. Now the big difference that you can't really notice is that print will always return 1.
Code: PHP
 
if(print 'foo'){
print print 'foos';
}
In this example since print always returns 1 the if statement will always be true so it will print print 'foos' which will print foos1. Echo doesn't return anything when content is printed. The benefit of using echo though, is that you can pass multiple strings to be echoed through parameters. It is actually faster, in fact, to echo multiple strings through parameters instead of concatenation.
Code: PHP
 
echo 'Hello ', 'World', '!';
Would actually be faster than
Code: PHP
 
echo 'Hello ' . 'World' . '!';

Echoing content instead of printing it is actually faster as a whole: http://www.phpbench.com/

Also some people think that echo and print are functions and as such must be called like so: echo() and print(). This is false, echo and print are not functions but language constructs and therefore do not need parenthesis.

Well I hope you got some useful information from this. If you have any questions or comments post them here ;)


For the full article - http://s4.zetaboards.com/vector/topic/8727668/1/#new
Posted Image

Professional web design/development services.http://wildandrewlee.com/
Off
Profile
Quote
Top
 
Maddy
Member Avatar
BAMMMMM!
Outline Documentations
G E N E R A L

Documentation accepted in to the General database
Posted Image
This is a work in progress ^^

"You still talk about it? You still care about it."


Tumblr - WeHeartIt - My Things - Twitter

The List
Life
<3
Off
Profile
Quote
Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Coding & Development · Next Topic »

Welcome Guest [Log In] [Register]
Outline Live
Loading..
Loading..