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

echo ( string $arg1 [, string $... ] );

PHP Echo Statement Example

<?php 
   echo "I am great.";
?> 

This will produce following result

I am great.

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

print ( string $arg1 [, string $... ] );

PHP Print Statement Example

<?php 
   print "I am the greatest.";
?> 

This will produce following result

I am the greatest.