Exact Difference Between Echo and Print in PHP

PHP Echo() and Print()

Print()

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"

Echo()

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s