Friday, September 3, 2010

Difference between echo and print

Speed : There is a difference between the two, but speed-wise it
should be irrelevant which one you use. echo is marginally faster  

Expression : print() behaves like a function in that you can do:
$ret = print "Hello World"; And $ret will be 1. That means that print
can be used as part of a more complex expression where echo cannot.

Example:
$b ? print "true" : print "false";

Parameter(s).  : The grammar is: echo expression [, expression[,expression] ... ] But echo ( expression, expression ) is not valid.
This would be valid: echo ("howdy"),("partner"); the same as: echo
"howdy","partner";
So, echo without parentheses can take multiple parameters, which get
concatenated:

echo "and a ", 1, 2, 3; // comma-separated without parentheses
echo ("and a 123"); // just one parameter with parentheses
print() can only take one parameter:
print ("and a 123");
print "and a 123";

1 comment:

  1. Thanks A Lord For Publish In Your Blog, This Is A Great Things To Learned Many Information. Keep Posting Many Blogs Like This.
    Web portal development company in chennai, Web portal development services in chennai

    ReplyDelete