php - Difference between var_dump,var_export & print_r -
what difference between var_dump
, var_export
, print_r
?
var_dump debugging purposes. var_dump
prints result.
// 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 debugging purposes, too, not include member's type. it's idea use if know types of elements in array, can misleading otherwise. print_r
default prints result, allows returning string instead using optional $return
parameter.
array ( [0] => [1] => [2] => 42 [3] => array ([0] => 42) )
var_export prints valid php code. useful if calculated values , want results constant in script. note var_export
can not handle reference cycles/recursive arrays, whereas var_dump
, print_r
check these. var_export
default prints result, allows returning string instead using optional $return
parameter.
array ( 0 => '', 2 => false, 2 => 42, 3 => array (0 => '42',), )
personally, think var_export
best compromise of concise , precise.
Comments
Post a Comment