Home > Backend Development > PHP Problem > What is the difference between echo and print in php?

What is the difference between echo and print in php?

烟雨青岚
Release: 2023-03-01 17:42:01
Original
3061 people have browsed it

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.

What is the difference between echo and print in php?

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template