A checkbox works a little differently than other inputs. A checkbox doesn't work by changing its value when it is checked or not. A checkbox either has a value when it is checked, or it doesn't have a value when it is not checked.
In HTML form submissions, only input elements that are considered "successful" are submitted with the form. For example, a disabled element is not considered "successful", so it will not be submitted.
In the case of a checkbox, a checkbox that is checked is considered "successful", but a checkbox that is unchecked is not considered "successful". Because of this, when checking the submitted form data in PHP, the element will only exist if the checkbox was checked.
So, if you define your input like this:
<input type="checkbox" id="checkbox1" name="checkbox1" value="1">
When the form is submitted, the request will include checkbox1=1
when the checkbox is checked, or the request will not include checkbox1
at all when the checkbox is not checked.
So, the final code you're looking for would be something like this:
<?php
// If the value exists in the request, it will be used. Otherwise, default to 0.
$cb1 = $_REQUEST['checkbox1'] ?? 0;
?>
<input type="checkbox" id="checkbox1" name="checkbox1" value="1" <?= $cb1 == 1 ? 'checked' : '' ?>>