What is the difference between print and echo in PHP [duplicate]

4

What would be the difference between using print or echo in PHP, since both print text on the screen.

When is it best to use one?

echo "echo";
print "print";
    
asked by anonymous 29.12.2014 / 17:13

1 answer

10

They are very similar. Some differences:

print

  • Returns 1 as a result and can be used in expressions

echo

  • Returns a type void , so it can not be used in expressions
  • It is possible to pass several arguments that must be printed separated by commas
  • It's slightly faster

I realize that print does not exist. I never had to use it as an expression that would be the only reason to use it.

    
29.12.2014 / 17:19