PHP

Output statement

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.

PHP echo Statement

echo is a language construct, and can be used with or without parentheses: echo or echo().

Display Strings

The following example shows how to display different strings with the echo command (also notice that the strings can contain HTML markup):

Example:

<?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.";
?>

Output:

Tutorialink.com
Tutorialink.com
Hello world!
PHP is easy
I'm about to learn PHP!
This string was made with multiple parameters

PHP print Statement

print is also a language construct, and can be used with or without parentheses: print or print().

Display Strings

The following example shows how to display different strings with the print command (also notice that the strings can contain HTML markup):

Example:

<?php
    print 'Tutorialink.com<br />';
    print 'Hello world!<br />';
    print 'PHP is easy<br />';
    print "I'm about to learn PHP!<br />";
?>

Output:

Tutorialink.com
Tutorialink.com
Hello world!
PHP is easy
I'm about to learn PHP!

Difference between echo and print Statements

There are some differences between echo and print:

echo print
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.
Note:

echo is marginally faster compared to print as echo does not return any value.




Subscribe us on Youtube

Share This Page on

Questions


hiren savaliya | 22-Jul-2016 12:38:27 pm

Explain this difference in detail


Admin | 24-Jul-2016 11:17:25 am

Thank you Sir, for give your feedback. Difference between echo and print is explained in detail in table...


Ask Question