
echo and print
PHP echo and print both are used to display the output in PHP. Both can be used with or without parenthese. The differences are small
- echo has no return value while print has a return value of 1, so it can ve used in expressions.
- echo can take multiple paramentrs whereas print can take only one argument.
- echo is marginally faster than print.
<?php
$name="John";
// without parenthese
echo $name;
print $name;
//with parenthese
echo ($name);
print ($name);
?>
echo has no return value while print has a return value of 1, so it can ve used in expressions.
<?php
$name="John";
$check = echo $name;
echo $check; // throw a error message of Parse/syntax error
$check = print $name;
//To test it returns or not
echo $check; //Output will be John
?>
echo can take multiple paramentrs whereas print can take only one argument.
<?php
$name = "John";
$profile = "PHP Developer";
$age = 25;
echo $name , $profile , $age, " years old"; //Output will be John PHP Developer 25 years old
print $name , $profile , $age, " years old"; // throw a error message (Parse error : syntax error)
?>