php - Why print_r() still exists? -


print_r(array('name'=> 'bob', 'age' => 20, 'sex' => 'man')); 

then :

array {     [name] => bob,     [age] => 20,     [sex] => man }  var_dump(array('name' => 'bob', 'age' => 20)); 

will display:

array(2) {     ['name'] => string(3) 'bob'     ['age'] => int(20) } 

var_dump perfect debug , better print_r. why print_r still exists? or print_r has advantage don't know

a big difference between print_r , var_dump print_r takes optional second argument, allows store contents in variable. example:

$debug = print_r($somearray, true); echo $debug; 

(note achieved var_dump using output control functions, though)

additionally, readability of print_r far better of var_dump:

var_dump:

array(3) {   [0]=>   int(1)   [1]=>   int(2)   [2]=>   array(3) {     [0]=>     string(1) "a"     [1]=>     string(1) "b"     [2]=>     string(1) "c"   } } 

print_r:

array (     [a] => apple     [b] => banana     [c] => array         (             [0] => x             [1] => y             [2] => z         ) ) 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -