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

What is the difference between echo and print in php

青灯夜游
青灯夜游Original
2019-05-08 11:49:508636browse

The difference between echo and print in php is: 1. Echo can output multiple strings at the same time, and print can only output one string at the same time; 2. Echo has no return value, while print has a return value, and its value Always 1 of type int.

What is the difference between echo and print in php

Dynamic output of HTML content in PHP is achieved through print and echo statements. The functions of the two are almost exactly the same, but there are also differences. The following article will tell you the similarities and differences between echo and print in php. I hope it will be helpful to you.

(Video tutorial recommendation: php video tutorial)

The similarities between echo and print in php

1. echo and print are both language structures (official documents explain it as language construct), not functions.

2. Echo and print can only output string, integer and int floating point data; they cannot print composite and resource type data.

3. 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.

The difference between echo and print in php

1. Echo can accept multiple string type parameters and can output multiple strings at the same time. print can only receive one parameter of string type; it can only output one string at the same time; the value printed by print can be directly assigned to a variable. Example: $a = print “123”

Note: When echo accepts multiple parameters, brackets cannot be used, that is, echo $arg1,$arg2 is Correct, echo($arg1,$arg2) will cause parsing errors

2. Echo output is faster than print; echo is relatively efficient

3 , echo has no return value, but print has a return value, and its value is always 1 of type int.

Related recommendations: php training

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!

Statement:
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