What is the purpose of the print_r() function in PHP and how can it be used to display the contents of an array?

The print_r() function in PHP is used to display human-readable information about a variable, especially arrays. It can be helpful for debugging purposes to see the structure and values stored in an array. To display the contents of an array using print_r(), simply pass the array variable as an argument to the function.

$array = array("apple", "banana", "cherry");
print_r($array);