In this tutorial, you shall learn the difference between echo() and print() functions in PHP, with example programs.

PHP echo vs print

PHP print() prints only a single string, while echo() can print one or more strings to output.

The syntax of print() is

print(string $expression): int

The syntax of echo is

echo(string ...$expressions): void

Examples

ADVERTISEMENT

1. Print

In the following example, we print a string "Hello World" to output using print().

PHP Program

<?php
print("Hello World");
?>

Output

PHP print()

2. Echo

In the following example, we print multiple strings using echo.

PHP Program

<?php
echo 'apple', 'banana', 'cherry';
?>

Output

Conclusion

In this PHP Tutorial, we learned the difference between echo and print in PHP, with examples.