PHP Output Statements (echo and print) : Tutorial




Echo and Print are language constructs that display strings. We have already seem echo statements. print does the same thing.

Difference between Print and Echo Statements

print :
It has a return type 1.
It takes in only single parameter, separated by a colon.

Syntax : int print ( string $arg )


echo :
It has return type void.
It takes in multiple parameters.

Syntax : void echo ( string $arg1 [, string $... ] )


e.g. :
echo "Hello,","my "," name is ", "Mike";
echo statement is little faster compaired to print.
echo and print statements are not fuctions, they are language constructs, so can be used with or without parentheses ().

Echo statement examples :

<?php

echo "Hello"," there!","<br>";
echo ("My name is Mike.<br>)";
echo "I love <b>PHP!</b>";

?>
Output

Hello there! My name is Mike. I love PHP!

Print statement examples :

<?php

print "Hello there!<br>";
print ("My name is Mike.<br>)";
print "I love <b>PHP!</b>";

?>
Output

Hello there! My name is Mike. I love PHP!