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.
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)
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 )
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!