PHP ZCE mock test, interview preparation, daily lessons under chalk talk

Tuesday, November 6, 2012

difference between echo and print in PHP

Question : What is the difference between echo and print in PHP? Why do you use one over the other?


Solution: 

print and echo both are more or less the same. Both are used to display strings. 

They are not actually functions in php. They are language constructs. Benefit of language construct is that you dont have to put parantheses for the argument list.

Differences are
  • print has a return value of 1 so it can be used in expressions whereas echo returns void.
  • echo can take multiple parameters. 
  • echo is slightly faster than print.

No comments:

Post a Comment