PHP echo and print Statements

There are two basic ways to get the output in PHP: echo and print , both are used to display the output on screen.

Difference between echo and print

  • echo has no return value while print has a return an integer value, which is 1
  • echo can take multiple parameters separated by comma (,) while print can take one argument.
  • echo is faster than print.

PHP echo Statements

echo can be used with or without parentheses: echo or echo(). some examples of echo

//echo with html text data
echo "<h1>PHP is scripting language </h1>";

//echo without parentheses
echo "Hello World!";

//echo with parentheses
echo ("Hello World!");

//echo with multiple parameters
echo "PHP ", "is a ", "server-side ","scripting language";

$string1=" Coding";
$string2=" at Qoify.com";
echo "Learn ".$string1.$string2;

$a=5;
$b=7;
echo $a+$b;

Output

PHP print Statements

Print can be used with or without parentheses: print or print(). some examples of print

//print with html text data
print "<h1>PHP is scripting language </h1>";

//print without parentheses
print "Hello World!";

//print with parentheses
print ("Hello World!");

$string1=" Coding";
$string2=" at Qoify.com";
print "Learn ".$string1.$string2;

$a=5;
$b=7;
$retun = print $a+$b;

// print return type check
print "Return type:".$retun;

Output