Echo and print Statements in PHP

There are two types of statements in PHP by which we can generate output, one is echo and another in print.

print and echo both are used to print the data in PHP and are used frequently in the programming.

1. Echo in PHP

What is an echo in PHP: echo is used to print data in the output screen.

It can be used with or without the parenthesis.
Example:

Result:

PHP!
I’m human being!
This is new way to learn many new things.

Result:

2. Print in PHP

What is print in PHP: print is used to print data in the output screen.

PHP echo and PHP print are doing the same work.

It can also be used with or without parenthesis.

Here we print the basic data we can also use to print object and complex data in PHP.

Example:

Result:

PHP!
I’m human being!
This is new way to learn many new things.

3 Echo Vs Print in PHP 

They are exactly the same working but they both have some similarities echo does not have any return value but print has a return value of 1.

And because of that print can be used in expressions.

Echo is very fast as compared to print. It can take multiple arguments but echo can take only one argument.

Read More

While loop in PHP Syntax and Example