Are there any best practices for pre-selecting checkboxes in PHP forms to improve user experience?

When pre-selecting checkboxes in PHP forms, it is important to consider the user experience. One best practice is to use the ternary operator in PHP to check if a checkbox should be pre-selected based on a condition. This can help improve usability by reducing the number of clicks required for the user to select their desired options.

<input type="checkbox" name="option1" <?php echo ($selectedOption == 'option1') ? 'checked' : ''; ?>> Option 1
<input type="checkbox" name="option2" <?php echo ($selectedOption == 'option2') ? 'checked' : ''; ?>> Option 2
<input type="checkbox" name="option3" <?php echo ($selectedOption == 'option3') ? 'checked' : ''; ?>> Option 3