What potential pitfalls should be considered when working with HTML tags in PHP arrays?

When working with HTML tags in PHP arrays, it is important to be cautious of potential security vulnerabilities such as cross-site scripting (XSS) attacks. To prevent this, it is recommended to properly sanitize and escape any user input that is being added to the array before outputting it to the browser. This can be done using functions like htmlspecialchars() or htmlentities() to encode special characters.

// Example of properly sanitizing user input before adding it to an array
$userInput = "<script>alert('XSS attack!');</script>";
$sanitizedInput = htmlspecialchars($userInput);

$htmlArray = array(
    'content' => $sanitizedInput
);

echo $htmlArray['content']; // This will output "<script>alert('XSS attack!');</script>"