How can multiple hidden buttons with different IDs be handled in PHP to avoid conflicts in JavaScript alerts?

When dealing with multiple hidden buttons with different IDs in PHP, one way to avoid conflicts in JavaScript alerts is to dynamically generate unique IDs for each button. This can be achieved by incorporating a unique identifier in the button IDs based on some criteria such as a database record ID or a timestamp.

<?php
// Generate unique IDs for hidden buttons
$button1_id = "button_" . uniqid();
$button2_id = "button_" . uniqid();
?>

<button id="<?php echo $button1_id; ?>" style="display:none">Button 1</button>
<button id="<?php echo $button2_id; ?>" style="display:none">Button 2</button>

<script>
// JavaScript alert for each button
document.getElementById("<?php echo $button1_id; ?>").addEventListener("click", function() {
    alert("Button 1 clicked");
});

document.getElementById("<?php echo $button2_id; ?>").addEventListener("click", function() {
    alert("Button 2 clicked");
});
</script>