Search form

Difference between Echo and Print in PHP

Key difference: An ‘echo’ and ‘print’ function is a language construct in PHP language. An ‘echo’ gives an output in one or more strings, while a ‘print’ gives the output only in one string.

Both, ‘echo’ and ‘print’ are not real functions in PHP, rather they are language constructs.

The ‘echo’ function is basically used to represent or command for an output string in PHP. Unlike the other output functions in various languages, this function does not actually behave like a function, instead it is a real construct, which behaves like a function. The ‘echo’ does not require any enclosing parentheses; hence the parameters to the command are passed without the parentheses. It also has a shortcut syntax, which immediately follows the opening tag with an equal sign.

The ‘echo’ syntax is as follows:

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

For example:

<?php

$str = "Hello world!";

echo $str;

?>

The ‘print’ function can be executed with or without the parentheses. Unlike ‘echo’, even this is not a pure function and is a construct in the PHP language. A ‘print’ returns the value along with the executed output. While executing the ‘print’ function, the programmer is limited to pass only one argument.