What is the difference between PHP echo and print ?

In PHP, the two basic constructs are used to get outputs which are echo and print. If firs of all we talk about echo it is the most basic way to display the result of program in php.


echo is not a kind of function,Because it is a language construct, hence, you can use it with or without parentheses such as echo or echo(). It do not return any value.

With the help of echo, we can display the value of a variable, string with single quotes or with double quotes and multiple strings separated by commas.

For Example:

   $myString1 = "Welcome to CODEHUNGER!";
   $myString2 = 'I am echo statement';
   echo $myString1.'<br>';
   echo $myString2;
   echo "<h5>I love using PHP!</h5>";




print is not a function. It is also a language construct like echo but it is always return a value either 0 or 1 so, we can use it to print the result of any regular expression.As compared to echo, the execution of print is slow. It can display only one string at a time.

For example:

  $myString1 = "Welcome to CODEHUNGER!";
  $myString2 = 'I am developer';
  print '<br>'.$myString2;
  print "<h5>I love using PHP! print by print statements</h5>";



Difference on key points in table format

echo is display strings and variable ,echo is not a really function but a language constructprint is display strings and variable ,print is not a really function but a language construct.
It Support with or without parenthesesit also like as echo Support with or without parentheses
echo can pass multiple string separated as ( $var1,$var2 ).
for example: echo $var1,$var2;
using print can doesn’t pass multiple argument i.e we can only pass one variable
For example: print($var);
echo is faster then printit is slower than echo
echo doesn’t return any valueprint always return 1

Shaiv Roy

Hy Myself shaiv roy, I am a passionate blogger and love to share ideas among people, I am having good experience with laravel, vue js, react, flutter and doing website and app development work from last 7 years.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button