Home  >  Article  >  Backend Development  >  What are the output statements in php?

What are the output statements in php?

青灯夜游
青灯夜游Original
2019-10-17 15:02:476116browse

What are the output statements in php?

echo

echo outputs one or more strings or variable values. It is a PHP statement, not a function, and has no return value.

print

#print is used to output information about one or more strings or variable values. It can only print out the values ​​of simple type variables (such as int, string), but cannot print arrays and objects. print has a return value, and they are all 1.

print_r

The print_r function is used to print easy-to-understand information about variables. Able to print complex data types, such as arrays and objects.

printf()

printf() is used to output a formatted string.

var_export()

var_export() function is used to output or return the string representation of a variable

var_dump()

var_dump() function is used to display structural information about one or more expressions, including the structural information of the expression, including the type and value of the expression. Arrays will expand values ​​recursively, showing their structure through indentation. Output directly to the browser.

sprintf()

The sprintf() function is also used for string formatting. For example: $formatted = sprintf ( " .2f ", '123.1' ) ;

To facilitate our memory, let's first compare these different output methods.

● echo - can output one or more strings

● print - can only output the value of simple type variables, such as int, string

● print_r - Can output the value of complex type variables, such as arrays, objects

● printf - function is used to format the output string, mainly used to replace the format string starting with % in the string.

● sprintf - function is also used for string formatting. This function is basically the same as the printf function, but it can save the converted result into a string variable instead of outputting it directly. (Because it is similar to printf, I will not give a detailed demonstration below)

● var_dump - prints information about variables, including the type and value of expressions, and displays its structure through indentation.

Tips: echo outputs faster than print. Echo is a PHP statement and has no return value. Print and print_r are PHP functions, and the functions have return values.

The return value of print is 1 (int type), and the return value of print_r is true (bool type).

For more PHP related knowledge, please visit php中文网!

The above is the detailed content of What are the output statements 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