What are potential pitfalls of using print_r to display array data in PHP templates?

Using print_r to display array data in PHP templates can potentially expose sensitive information to users, as it displays the raw data structure of the array. To prevent this, you should use htmlentities to escape the output and prevent any HTML or script injection attacks.

<?php
$data = array('username' => 'john_doe', 'password' => 'secret123');
echo '<pre>' . htmlentities(print_r($data, true)) . '</pre>';
?>