var_dump,var_export&之间的区别print_r [英] Difference between var_dump,var_export & print_r
问题描述
var_dump
,var_export
和print_r
有什么区别?
推荐答案
var_dump 用于调试目的. var_dump
始终打印结果.
// var_dump(array('', false, 42, array('42')));
array(4) {
[0]=> string(0) ""
[1]=> bool(false)
[2]=> int(42)
[3]=> array(1) {[0]=>string(2) "42")}
}
print_r 也用于调试目的,但不包括成员的类型.如果您知道数组中元素的类型,则最好使用,但否则可能会引起误解.默认情况下,print_r
打印结果,但是允许通过使用可选的$return
参数作为字符串返回.
print_r is for debugging purposes, too, but does not include the member's type. It's a good idea to use if you know the types of elements in your array, but can be misleading otherwise. print_r
by default prints the result, but allows returning as string instead by using the optional $return
parameter.
Array (
[0] =>
[1] =>
[2] => 42
[3] => Array ([0] => 42)
)
var_export 打印有效的php代码.如果您计算了一些值并希望结果在另一个脚本中作为常量,则很有用.请注意,var_export
无法处理参考循环/递归数组,而var_dump
和print_r
会检查它们.默认情况下,var_export
打印结果,但是允许通过使用可选的$return
参数作为字符串返回.
var_export prints valid php code. Useful if you calculated some values and want the results as a constant in another script. Note that var_export
can not handle reference cycles/recursive arrays, whereas var_dump
and print_r
check for these. var_export
by default prints the result, but allows returning as string instead by using the optional $return
parameter.
array (
0 => '',
1 => false,
2 => 42,
3 => array (0 => '42',),
)
我个人认为var_export
是简洁和精确的最佳折衷.
Personally, I think var_export
is the best compromise of concise and precise.
这篇关于var_dump,var_export&之间的区别print_r的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!