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

</>
Copy
print(string $expression): int

The syntax of echo is

</>
Copy
echo(string ...$expressions): void

Examples

1. Print

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

PHP Program

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

Output

PHP print()

2. Echo

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

PHP Program

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

Output

Conclusion

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