PHP echo and print Functions

PHP Tutorial

PHP echo and print Functions

Both PHP echo and print Functions are used to output text, variables, HTML, and results to the browser.

They look similar, but there are a few differences.


1. PHP echo

 Features:

  • Can output multiple values

  • Faster than print

  • No return value

  • Most commonly used

 Example:


 Echo multiple strings:



2. PHP print

 Features:

  • Can output only one value

  • Slightly slower than echo

  • Returns 1 → can be used in expressions

 Example:


 Print cannot output multiple values:



Echo vs Print — Summary Table

Feature echo print
Outputs multiple items ✔ Yes ❌ No
Speed Faster Slightly slower
Return value No Yes (returns 1)
Usage Very common Less common
Parentheses allowed Optional Optional

Using echo / print with Variables

Example:


 


Using echo / print with HTML



Using Concatenation (.)



 Example Showing Both


 


 When to Use What?

Use Case Best Option
Most PHP output echo
Expression-based output print
Printing multiple things together echo
Working with return values print

If you want, I can continue with the next topic:
👉 PHP Data Types
👉 PHP Strings
👉 PHP Operators
👉 PHP Constants

You may also like...