echo and print function
PHP echo and print both are PHP function. Both are used to display the output in PHP.
The differences are small:
The major differences to echo are that print only accepts a single argument and always returns echo can take multiple parameters while print can take one argument. echo is faster than print.
The PHP echo function
The echo function can be used with or without parentheses: echo or echo(). Basically echo is not actually a function this is a language construct , so you are not required to use parentheses with using it.
Example 1 : single argument
<?php
$name="Jawab Adda";
echo $name;
//or
echo ($name);
?>
Output
Jawab Adda Jawab Adda
Example 2 : multiple argument
<?php
$webstename = " JawabAdda";
$URL = " http://www.jawabadda.com/";
echo "Website Name-".$webstename, " URL-".$URL;
?>
Output
Website Name- JawabAdda URL- http://www.jawabadda.com/
The PHP print function
The print statement can be used with or without parentheses: print or print(). Basically print is not actually a real function this is a language construct , so you are not required to use parentheses with using it.
Example 1 : single argument
<?php
$name="Jawab Adda";
print $name;
//or
print ($name);
?>
Output
Jawab Adda Jawab Adda
Example 2 : multiple argument
<?php
$webstename = " JawabAdda";
$URL = " http://www.jawabadda.com/";
print "Website Name-".$webstename, " URL-".$URL;
?>
Output
Parse error: syntax error, unexpected