Home  >  Article  >  Backend Development  >  How to achieve output in PHP? What are the output methods of PHP?

How to achieve output in PHP? What are the output methods of PHP?

青灯夜游
青灯夜游Original
2018-12-28 16:01:1219481browse

In PHP, you can use echo statement, print statement, printf(), print_r(), var_dump() to achieve output. Let's take a look at these output methods. I hope it will be helpful to everyone.

How to achieve output in PHP? What are the output methods of PHP?

echo statement

echo is a language construct that can be used with or without parentheses: Echo or echo() can be used for output, and it is the most commonly used output statement. Example:

Output:

How to achieve output in PHP? What are the output methods of PHP?

Description: In normal times, the output of echo or echo() is the same, only when multiple parameters are passed to Echo statement, when outputting, using parentheses will generate a parsing error.

print statement

The print statement can also achieve output and has a return value. It returns 1 on success and 0 on failure; therefore it can be used in expressions.

Note: The print statement can also be used with or without parentheses, there is not much difference.

Output:

How to achieve output in PHP? What are the output methods of PHP?

printf() function

printf() function also Output can be achieved, ordinary strings can be output, and output can also be formatted. Example:

Output:

How to achieve output in PHP? What are the output methods of PHP?

print_r()

print_r() Functions are used to output variables and can display information about this variable in a format that is easy for humans to read.

 'apple', 'b' => 'banana', 'c' => array ('x','y','z'));
echo "
";
print_r ($a);
echo "
"; ?>

Output:

How to achieve output in PHP? What are the output methods of PHP?

var_dump()

var_dump() function For output variables, you can display the structured information of the variable, such as type and value.

Output:

How to achieve output in PHP? What are the output methods of PHP?

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's learning.

The above is the detailed content of How to achieve output in PHP? What are the output methods of 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
Previous article:What is CMSNext article:What is CMS