What is the purpose of using print_r in PHP and how does it work with arrays?

The purpose of using print_r in PHP is to display human-readable information about a variable, especially arrays. It helps developers debug and understand the structure and contents of an array easily. When used with arrays, print_r will display the keys and values of each element in the array.

// Sample array
$fruits = array("apple", "banana", "cherry");

// Display the contents of the array using print_r
print_r($fruits);