How can the context switch to HTML affect PHP array values when using print_r or var_dump?

When a context switch to HTML occurs while using functions like print_r or var_dump in PHP, the array values may be displayed as HTML entities, making it difficult to read or debug. To solve this issue, you can use the htmlspecialchars function to encode the array values before printing them to the HTML output.

<?php
// Sample array
$array = array('a' => '<b>bold</b>', 'c' => '"quoted"');

// Encode array values before printing
echo '<pre>';
print_r(array_map('htmlspecialchars', $array));
echo '</pre>';
?>