PHP echo and print Statements

In PHP, both echo and print are used to output data to the screen. While they are similar, there are a few key differences:


echo Statement

  • Can take multiple parameters (though rarely used that way).

  • Faster than print (slightly, due to no return value).

  • Does not return a value.

Syntax:

echo "Hello, World!";

Multiple parameters (less common):

echo "Hello ", "World!";

print Statement

  • Can only take one argument.

  • Returns 1, so it can be used in expressions.

  • Slightly slower than echo.

Syntax:

print "Hello, World!";

Used in an expression:

$success = print "Hello!";

Key Differences Summary

Feature echo print
Parameters Multiple One
Return Value No Yes (always 1)
Speed Slightly faster Slightly slower
Usage in Expr. No Yes