What are some alternative methods to echo out arrays in PHP besides json_encode()?

When echoing out arrays in PHP, using json_encode() is a common and effective method to convert arrays into a JSON string. However, there are alternative methods available such as using print_r() or var_dump() to display the array structure in a more human-readable format.

// Using print_r() to echo out the array
$array = [1, 2, 3, 4, 5];
echo "<pre>";
print_r($array);
echo "</pre>";

// Using var_dump() to echo out the array
$array = ['apple' => 'red', 'banana' => 'yellow', 'grape' => 'purple'];
echo "<pre>";
var_dump($array);
echo "</pre>";