How can the method gettests impact pre-selecting checkboxes in PHP?

When pre-selecting checkboxes in PHP, the method gettests can be used to retrieve the selected values from the form submission. By checking if the value of each checkbox exists in the array returned by gettests, we can determine which checkboxes were selected and set the "checked" attribute accordingly in the HTML output.

// Assume $checkboxValues is an array of values from the checkboxes
$selectedTests = $_GET['selectedTests'] ?? [];

// Loop through each checkbox and check if its value is in the selectedTests array
foreach ($checkboxValues as $value) {
    $checked = in_array($value, $selectedTests) ? 'checked' : '';
    echo '<input type="checkbox" name="selectedTests[]" value="' . $value . '" ' . $checked . '>';
}