What’s the difference between print and echo in PHP

Asked

Viewed 4,417 times

4

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

When it is most advisable to use which?

echo "echo";
print "print";

1 answer

14


They are very similar. Some differences:

print

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

echo

  • Returns a type void, therefore cannot be used in expressions
  • It is possible to pass several arguments that should be printed separated by a comma
  • Is slightly faster

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

  • 1

    I pretend that print does not exist. The smartest phrase I read today.

  • 1

    And she was the first to read :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.