PHP Echo / Print

Simply, the echo statement is used to output data. In most cases, anything output by echo ends up viewable in the browser. You could also have used the print() function in place of the echo statement. Using echo or print() is a matter of taste; when you look at other people’s scripts, you might see either use.Whereas echo is a statement, print() is a function. A function is a command that performs an action, usually modified in some way by data provided for it. Data sent to a function is almost always placed in parentheses after the functionname. In this case, you could have sent the print() function a collection of characters or a string. Strings must always be enclosed in quotation marks, either single or double.

For example:

<?php print(“Hello Web!”); ?>

Difference Between Echo and Print

ECHO

PRINT

Parameters

echo can take more than one parameter when used without parentheses.

print only takes one parameter.

Return value

echo does not return any value

print always returns 1 (integer)

Syntax

void echo (string $arg1[string $… ] )

int print (string $arg)

What is it?

In PHP echo is not a function but a language construct.

In PHP print is not a real function but a language construct. However, it behaves like a function in that it returns a value.

Anuj Kumar

This is Anuj Kumar. I’m a professional web developer with 4+ year experience. I write blogs in my free time. I love to learn new technologies and share with others. I founded PHPGurukul in September 2015. The main aim of this website to provide PHP, Jquery, MySQL, PHP Oops and other web development tutorials. .