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 is perfect to debug and much better than print_r. But why print_r still exists? or print_r has some advantage i don’t know
A big difference between
print_randvar_dumpis thatprint_rtakes an optional second argument, which allows you to the store the contents in a variable. For example:(Note that this could also be achieved for
var_dumpusing output control functions, though)Additionally, the readability of
print_ris far better than that ofvar_dump:var_dump:
print_r: