Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

difference between echo and print

Status
Not open for further replies.

aardvark92

Programmer
Oct 15, 2004
138
US
I've been wondering about this for a while. . .

What, practically speaking, is the difference between the print() and echo() constructs? According to php.net, print returns a value (always 1), while echo does not. Also, print outputs a string, while echo outputs one or more strings.

So I guess the following work:
Code:
$value = print "string"; // $value = 1
echo "two", " strings";

while these do not:
Code:
$value = echo "string";
print "two", " strings";

But the output of multiple strings could be simulated with print by comcatenating them, and the return value could be simulated with echo by assigning $value = 1.

So what I'm trying to get at is, practically speaking, does it make a difference which one is used? Is it more a matter of style? Are there any situations in which print or echo is clearly better than the other?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top