Difference between print_r() and var_dump()

print_r() and var_dump() both are used for the array.

print_r()

It 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.
example:-


<?php 
$employees=array("Sachin","Rohit","Virat","M.S Dhoni");
print_r($employees);
?>
Output:- Array ( [0] => Sachin [1] => Rohit [2] => Virat [3] => M.S Dhoni )

Try it Yourself

var_dump()

It displays structured information about variables/expressions including its type and value.
example:-


<?php 
$employees=array("Sachin","Rohit","Virat","M.S Dhoni");
var_dump($employees);
?>
Output:-
array(4) { [0]=> string(6) “Sachin” [1]=> string(5) “Rohit” [2]=> string(5) “Virat” [3]=> string(9) “M.S Dhoni” }

Try it Yourself