How can the PHP script be modified to ensure that only the clicked checkbox remains checked upon submission?

The issue can be solved by modifying the PHP script to only check the checkbox that was clicked by the user upon form submission. This can be achieved by assigning a unique value to each checkbox input and then checking if that value matches the submitted value. If it does, the checkbox will be checked, otherwise it will remain unchecked.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $checkbox_values = array("checkbox1", "checkbox2", "checkbox3");

    foreach ($checkbox_values as $value) {
        if ($_POST[$value] == $value) {
            echo "<input type='checkbox' name='$value' value='$value' checked>";
        } else {
            echo "<input type='checkbox' name='$value' value='$value'>";
        }
    }
}
?>