Like echo, print is a language construct of PHP, not a function. The use of print is almost identical to echo. There are, however, some subtle differences.
First of all, print returns 'TRUE' if it was able to successfully output the string passed to it or 'FALSE' if it was not. The fact that print' returns a value allows it to be used in situations where echo can not be used. Take an expression like the following:
<?php $var ? print 'true' : print 'false'; ?>
In this example, we are using the ternary operator to decide what action to take. The ternary operator is a very simple if-else statement. It has three different parts. The first is the evaluation expression, which in our case is simply $var. The next expression, print 'true', is evaluated only if the first expression is TRUE. The last expression, print 'false', is evaluated if the first is FALSE. It can be read as, 'If $var is true print true, otherwise, print false.
If we were to replace the 'print' statements with 'echo' statements, it would result in a parse error. Because echo does not return a value it would not result in a valid expression, whereas print would.
Another difference between print and echo is the later is able to take multiple arguments. As we saw when we examined echo, you can pass multiple strings to it separated by commas. The print construct, on the other hand, will only accept one argument or string.
Finally, it has been argued that print is not quite as fast as echo is. While this may be true, and verified by our tests, in order to see any noticeable difference we would need to use hundreds of thousands of print statements in a single script. Even then, the difference would only be very slight. if your application relies on efficiency and speed of execution, you may be better off using echo. For most applications, however, the difference will not be seen.