What is the difference between print_r and print

王林
Release: 2023-03-01 17:56:01
Original
5549 people have browsed it

The difference between print_r and print is: print is used to output one or more strings. It can only print out the value of simple type variables; the print_r() function can print out the value of complex type variables. Print out the array content and structure, and display the keys and elements in a certain format.

What is the difference between print_r and print

Analysis of the difference between print_r and print:

print()

print() To output one or more strings. Like echo, it is not actually a function. Print has a return value, but echo does not. When its execution fails, it returns false, and if it succeeds, it returns true. It is slightly slower than echo. It can only print out the values of simple type variables, such as int and string.

For example: (write the value of string variable $str to the output)

Copy after login

print_r() function

print_r() function can print Get the value of a complex type variable. Use print_r() to print out the entire array content and structure, and display the keys and elements in a certain format. In fact, it's not just for printing, but for printing easy-to-understand information about variables.

For example: (print array $age)

 //运行结果:Array ( [0] => 18 [1] => 20 [2] => 24 )
Copy after login

If you want to learn more related knowledge, please visitphp Chinese website.

The above is the detailed content of What is the difference between print_r and print. 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!