What is the difference between echo and print in php

青灯夜游
Release: 2023-03-08 08:22:02
Original
5104 people have browsed it

Difference: 1. Echo can output multiple strings, while print can only output one string; 2. Echo outputs faster than print, and echo is relatively efficient; 3. Echo has no return value. Print has a return value, and its value is always "1" of type int.

What is the difference between echo and print in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

echo

echo() function outputs one or more strings.

Note: The echo() function is not actually a function, so you don't have to use parentheses with it. However, if you want to pass more than one argument to echo(), using parentheses will generate a parsing error.

print()

print() function outputs one or more strings.

Note: The print() function is not actually a function, so you don't have to use parentheses with it.

[Recommended study: "PHP Video Tutorial"]

The difference between echo and print

1. Echo is acceptable Multiple string type parameters 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, and echo($arg1,$arg2) will Resulting in parsing errors

2. The output speed of echo is faster than that of print; the efficiency of echo is relatively fast

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

For more programming related knowledge, please visit:Programming Video! !

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!