In PHP there are two basic ways to get output: echo
and print
.
In this tutorial we use echo (and print) in almost every example.
So, this chapter contains a little more info about those two output statements.
echo is a language construct, and can be used with or without parentheses: echo or echo().
The following example shows how to display different strings with the echo command (also notice that the strings can contain HTML markup):
<?php
echo 'Tutorialink.com<br />';
echo 'Hello world!<br />';
echo 'PHP is easy<br />';
echo "I'm about to learn PHP!<br />";
echo "This", " string", " was", " made", " with multiple parameters.";
?>
print is also a language construct, and can be used with or without parentheses: print or print().
The following example shows how to display different strings with the print command (also notice that the strings can contain HTML markup):
<?php
print 'Tutorialink.com<br />';
print 'Hello world!<br />';
print 'PHP is easy<br />';
print "I'm about to learn PHP!<br />";
?>
There are some differences between echo and print:
echo | |
echo statement can be used with parentheses echo( ) or without parentheses echo. | Print statement can be used with parentheses print( ) or without parentheses print. |
echo can pass multiple string separated as , |
using print can doesn't pass multiple argument. |
echo doesn't return any value. | print always return 1. |
echo is faster then print. | it is slower than echo. |
echo
is marginally faster compared to print
as echo
does not return any value.
Ask Question