php var_dump() 与 print_r() [英] php var_dump() vs print_r()
问题描述
var_dump()
和 print_r()
在将数组作为字符串吐出方面有什么区别?
What is the difference between var_dump()
and print_r()
in terms of spitting out an array as string?
推荐答案
var_dump
函数显示有关变量/表达式的结构化信息,包括其类型和值强>.数组以缩进的值进行递归探索以显示结构.它还显示哪些数组值和对象属性是引用.
The var_dump
function displays structured information about variables/expressions including its type and value. Arrays are explored recursively with values indented to show structure. It also shows which array values and object properties are references.
print_r()
以人类可读的方式显示有关变量的信息.数组值将以显示键和元素的格式呈现.类似的符号用于对象.
The print_r()
displays information about a variable in a way that's readable by humans. array values will be presented in a format that shows keys and elements. Similar notation is used for objects.
示例:
$obj = (object) array('qualitypoint', 'technologies', 'India');
var_dump($obj)
将在屏幕下方显示输出.
var_dump($obj)
will display below output in the screen.
object(stdClass)#1 (3) {
[0]=> string(12) "qualitypoint"
[1]=> string(12) "technologies"
[2]=> string(5) "India"
}
并且,print_r($obj)
将在屏幕下方显示输出.
And, print_r($obj)
will display below output in the screen.
stdClass Object (
[0] => qualitypoint
[1] => technologies
[2] => India
)
更多信息
这篇关于php var_dump() 与 print_r()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!