Differences in php output statements

王林
Release: 2023-02-24 13:28:02
Original
2878 people have browsed it

Differences in php output statements

PHP echo and print statements

Difference between echo and print:

echo - Able to output more than one string

print - Can only output one string and always returns 1

Tip: echo is slightly faster than print because it does not return any value .

PHP echo statement

echo is a language structure that can be used with or without parentheses: echo or echo().

PHP print statement

print is also a language structure and can be used with or without parentheses: print or print().

Common output statements

echo()
You can output multiple values ​​at one time, separated by commas. echo is a language construct, not a real function, so it cannot be used as part of an expression.

print()

The function print() prints a value (its parameter) and returns true if the string is successfully displayed, otherwise it returns false.

print_r()
Strings and numbers can be simply printed out, while arrays are displayed as a bracketed list of keys and values, starting with Array. But the results of print_r() outputting Boolean values ​​and NULL are meaningless, because they all print "\n". Therefore, using the var_dump() function is more suitable for debugging.

var_dump()
Determine the type and length of a variable, and output the value of the variable. If the variable has a value, the value of the variable is output and the data type is returned. This function displays structural information about one or more expressions, including the expression's type and value. Arrays will expand values ​​recursively, showing their structure through indentation.

The result of using echo is:

Differences in php output statements

The result of using print() is:

Differences in php output statements

The output result of using print_r() is:

Differences in php output statements

The output result of using var_dump() is:

Differences in php output statements

Recommended tutorial: PHP video tutorial

The above is the detailed content of Differences in php output statements. 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