The difference between echo and print is: 1. Echo can accept N string type parameters, while print can only receive 1 string type parameter; 2. Echo has no return value, but print has a return value. , its value is always 1 of type int.
The two are similar:
echo and print are both language structures (official documents explain it as language construct) ;
echo and print are both used to output strings;
When there is only one parameter at the same time, the parentheses (parenthesis) after echo and print are optional, that is: echo ($argument1) is equivalent to echo $argument1, print(argument) is equivalent to print argument;
echo and print will convert the parameters and try to convert them to string type before outputting.
The difference between the two:
echo can accept N string type parameters(Note: When there are multiple parameters, it cannot Use parentheses, that is, echo $arg1, $arg2 is correct, echo($arg1,$arg2) will cause a parsing error); print can only receive 1 parameter of string type;
echo has no return value; print has a return value, and its value is always 1 of type int.
Here is a quote from the original PHP document: "The major differences to echo are that print only accepts a single argument and always returns 1."
Recommended tutorial: "php tutorial》
The above is the detailed content of What is the difference between echo and print in php?. For more information, please follow other related articles on the PHP Chinese website!