What is the correct way to output a variable in a hidden element in PHP?

When outputting a variable in a hidden element in PHP, you need to use the `htmlspecialchars()` function to prevent any potential XSS attacks. This function converts special characters to HTML entities, ensuring that the variable's value is safely displayed in the hidden element.

<?php
// Variable to be output in hidden element
$hiddenVariable = "sensitive_data";

// Output the variable in a hidden element
echo '<input type="hidden" name="hidden_field" value="' . htmlspecialchars($hiddenVariable) . '">';
?>