In PHP, echo or print is used for output on screen.
echo | |
---|---|
Returns no value | Returns 1 |
Can be use with or without parentheses | Can be use with or without parentheses |
Accept more than one parameters | Accept only one parameter |
echo examples
Display variable value
<?php
$a = 30;
echo $a;
?>
Display text
<?php
$name = "PHP";
echo $name;
?>
Print examples
Display variable value
<?php
$a = 30;
print $a;
?>
Display text
<?php
$name = "PHP";
print $name;
?>
echo and Print with or without parenthesis
<?php
$a = 30;
echo $a;
$b = 20;
echo($b);
?>
<?php
$a = 30;
print $a;
$b = 20;
print($b);
?>
echo and Print without parenthesis does not required any space after echo or print.
<?php
$a = 30;
echo$a;
print$a;
echo"Hello";
print"World";
?>