saftutorials.com
PHP Outputs Tutorial

There are two basic PHP functions which are commonly used to output data to the screen. Both are PHP pre-built function.

PHP echo() / echo function.

PHP print() / print function.


echo and print function both are same except some minor difference.

What is different between PHP Echo and Print?

These differences are given below

echo can take multiple arguments while print can take only one argument.

echo has no return value while print has a return value of 1.

echo is slightly faster than print.

Example of echo statement

<!DOCTYPE html>
<html>
<body>
<?php
$message = "this variable";
echo "<h1>echo is used to output data to the screen</h1><br>";
echo "Hello, John!<br>";
echo "This is string<br>";
print ("echo with parentheses<br>");
echo "This ", "string merge with ".$message;
?>
</body>
</html>


The above code produces the following results

Outputs: echo is used to output data to the screen

Hello, John!

This is string

echo with parentheses

This string merge with this variable


Example of print statement

<!DOCTYPE html>
<html>
<body>
<?php
$message = "this variable";
print "<h1>print is used to output data to the screen</h1><br>";
print "Hello, John!<br>";
print "This is string<br>";
print ("Print with parentheses<br>");
print "This string merge with ".$message;
?>
</body>
</html>


The above code produces the following results

Outputs: print is used to output data to the screen

Hello, John!

This is string

print with parentheses

This string merge with this variable

Find us on

Facebook Google Plus Twitter Pinterest YouTube

web statistic