What is the best practice for pre-selecting checkboxes in PHP forms?

When pre-selecting checkboxes in PHP forms, you need to check if the checkbox value matches the value stored in the database and add the "checked" attribute to the checkbox input tag if they match. This can be achieved by using a conditional statement within the HTML input tag.

// Assume $checkboxValue is the value stored in the database
$checkboxValue = "1";

// Check if the checkbox value matches the stored value and add the "checked" attribute
<input type="checkbox" name="checkbox_name" value="1" <?php if($checkboxValue == "1") { echo "checked"; } ?>>