Difference Between Echo and Print in PHP


boolean print (argument)
  • print() is capable of displaying both strings and variables.
  • print() returns a Boolean Type, expresses a true value.
$language = "PHP";
$authour = "Rasmus Lerdorf";
$starts = 1994;

print $language;  // Resulting "PHP";

print $language.''.$authour;  
// Resulting "PHPRasmus Lerdorf"
// Multiple strings display using Concatenation(.) Operator. 
// print() has restricted of use comma(,) separator to display
multiple string, only echo() will do.

$year = print $starts;  // Resulting "1994" 

print $year; // Resulting Boolean Type "1"


void echo (string argument1 [, ...string argumentN])
  • echo() is capable of displaying multiple strings and variables.
  • echo() doesn’t returns a Boolean Type, because it returns void.
$language = "PHP";
$authour = "Rasmus Lerdorf";
$starts = 1994;
echo $language; // Resulting "PHP"

echo $language,$authour; 
// Resulting "PHPRasmus Lerdorf"
// Displaying multiple string using comma(,) separator.

$year = echo $starts;  
// Syntax Error, Because print() has capable to result the output.

*echo() function is a faster, because it returns nothing, whereas print() returns a Boolean value.