How can PHP be integrated with HTML to dynamically open modal boxes based on certain conditions?

To dynamically open modal boxes based on certain conditions in PHP integrated with HTML, you can use PHP to generate the necessary HTML and JavaScript code to trigger the modal box when the condition is met.

<?php
$condition = true; // Set your condition here

if ($condition) {
    echo '<script>';
    echo 'document.addEventListener("DOMContentLoaded", function() {';
    echo 'document.getElementById("myModal").style.display = "block";';
    echo '});';
    echo '</script>';
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Modal Box Example</title>
    <style>
        #myModal {
            display: none;
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0,0,0,0.4);
        }
    </style>
</head>
<body>

<div id="myModal">
    <div>
        <h2>Modal Box</h2>
        <p>This is a modal box that opens dynamically based on a condition.</p>
    </div>
</div>

</body>
</html>