PHP Echo & Print

In PHP, whenever we want to display anything or see the output, we use Echo and Print Statements.

Echo Statement

echo() statement takes a string of text and sends it as part of the Web page to the browser. The browser then displays the text to the visitor it is followed by a semicolon (;) at the end of the line which means that we have reached the end of the current statement and it should look for a new statement to follow or it is the end of the PHP code. Echo is not a function, it is a language construct as when we use function in PHP, it has a particular format

Syntax

PHP Echo Statement Example

This will produce following result

Print Statement

This is also used to send the output to the screen. An alternative to echo() is the print() statement. Print works exactly the same as Echo but the only difference is that it returns a value (true). We can use print() instead of echo() anywhere in our code wherever we like.

Syntax

PHP Print Statement Example

This will produce following result